Exemplo n.º 1
0
 function getSearchParams($stage, $assignedto, $dates)
 {
     $listSearchParams = array();
     $conditions = array();
     array_push($conditions, array("sales_stage", "e", $stage));
     if ($assignedto == '') {
         $currenUserModel = Users_Record_Model::getCurrentUserModel();
         $assignedto = $currenUserModel->getId();
     }
     if ($assignedto != 'all') {
         $ownerType = vtws_getOwnerType($assignedto);
         if ($ownerType == 'Users') {
             array_push($conditions, array("assigned_user_id", "e", getUserFullName($assignedto)));
         } else {
             $groupName = getGroupName($assignedto);
             $groupName = $groupName[0];
             array_push($conditions, array("assigned_user_id", "e", $groupName));
         }
     }
     if (!empty($dates)) {
         array_push($conditions, array("closingdate", "bw", $dates['start'] . ',' . $dates['end']));
     }
     $listSearchParams[] = $conditions;
     return '&search_params=' . json_encode($listSearchParams);
 }
Exemplo n.º 2
0
 public function process(Vtiger_Request $request)
 {
     $recordId = $request->get('record');
     $modules = $request->get('modules');
     $assignId = $request->get('assigned_user_id');
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $entityValues = array();
     $entityValues['transferRelatedRecordsTo'] = $request->get('transferModule');
     //■権限なぜか、エラーになるので権限を固定するinouchi
     //$entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType($assignId), $assignId);
     $entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType(1), 1);
     $entityValues['leadId'] = vtws_getWebserviceEntityId($request->getModule(), $recordId);
     $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $request->getModule());
     $convertLeadFields = $recordModel->getConvertLeadFields();
     $availableModules = array('Accounts', 'Contacts', 'Potentials');
     foreach ($availableModules as $module) {
         if (vtlib_isModuleActive($module) && in_array($module, $modules)) {
             $entityValues['entities'][$module]['create'] = true;
             $entityValues['entities'][$module]['name'] = $module;
             foreach ($convertLeadFields[$module] as $fieldModel) {
                 $fieldName = $fieldModel->getName();
                 $fieldValue = $request->get($fieldName);
                 //Potential Amount Field value converting into DB format
                 if ($fieldModel->getFieldDataType() === 'currency') {
                     $fieldValue = Vtiger_Currency_UIType::convertToDBFormat($fieldValue);
                 } elseif ($fieldModel->getFieldDataType() === 'date') {
                     $fieldValue = DateTimeField::convertToDBFormat($fieldValue);
                 } elseif ($fieldModel->getFieldDataType() === 'reference' && $fieldValue) {
                     $ids = vtws_getIdComponents($fieldValue);
                     if (count($ids) === 1) {
                         $fieldValue = vtws_getWebserviceEntityId(getSalesEntityType($fieldValue), $fieldValue);
                     }
                 }
                 $entityValues['entities'][$module][$fieldName] = $fieldValue;
             }
         }
     }
     try {
         $result = vtws_convertlead($entityValues, $currentUser);
     } catch (Exception $e) {
         $this->showError($request, $e);
         exit;
     }
     if (!empty($result['Accounts'])) {
         $accountIdComponents = vtws_getIdComponents($result['Accounts']);
         $accountId = $accountIdComponents[1];
     }
     if (!empty($result['Contacts'])) {
         $contactIdComponents = vtws_getIdComponents($result['Contacts']);
         $contactId = $contactIdComponents[1];
     }
     if (!empty($accountId)) {
         header("Location: index.php?view=Detail&module=Accounts&record={$accountId}");
     } elseif (!empty($contactId)) {
         header("Location: index.php?view=Detail&module=Contacts&record={$contactId}");
     } else {
         $this->showError($request);
         exit;
     }
 }
function HelpDesk_notifyOwnerOnTicketChange($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $isNew = $entityData->isNew();
    if (!$isNew) {
        $reply = 'Re : ';
    } else {
        $reply = '';
    }
    // SalesPlatform.ru begin
    $subject = ' [ ' . getTranslatedString('Ticket No', $moduleName) . ' ' . $entityData->get('ticket_no') . ' ] ' . $reply . $entityData->get('ticket_title');
    //$subject = $entityData->get('ticket_no') . ' [ '.getTranslatedString('LBL_TICKET_ID', $moduleName)
    //					.' : '.$entityId.' ] '.$reply.$entityData->get('ticket_title');
    // SalesPlatform.ru end
    $email_body = HelpDesk::getTicketEmailContents($entityData, true);
    if (PerformancePrefs::getBoolean('NOTIFY_OWNER_EMAILS', true) === true) {
        //send mail to the assigned to user and the parent to whom this ticket is assigned
        require_once 'modules/Emails/mail.php';
        $wsAssignedUserId = $entityData->get('assigned_user_id');
        $userIdParts = explode('x', $wsAssignedUserId);
        $ownerId = $userIdParts[1];
        $ownerType = vtws_getOwnerType($ownerId);
        if ($ownerType == 'Users') {
            $to_email = getUserEmailId('id', $ownerId);
        }
        if ($ownerType == 'Groups') {
            $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
        }
        if ($to_email != '') {
            if ($isNew) {
                $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
            } else {
                $entityDelta = new VTEntityDelta();
                $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
                $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
                $ownerHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'assigned_user_id');
                $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
                if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $solutionHasChanged || $ownerHasChanged || $descriptionHasChanged) {
                    $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
                }
            }
            $mail_status_str = $to_email . "=" . $mail_status . "&&&";
        } else {
            $mail_status_str = "'" . $to_email . "'=0&&&";
        }
        if ($mail_status != '') {
            $mail_error_status = getMailErrorString($mail_status_str);
        }
    }
}
Exemplo n.º 4
0
 function sanitizeOwnerFields($row, $meta, $t = null)
 {
     global $adb;
     $ownerFields = $meta->getOwnerFields();
     foreach ($ownerFields as $index => $field) {
         if (isset($row[$field]) && $row[$field] != null) {
             $ownerType = vtws_getOwnerType($row[$field]);
             $webserviceObject = VtigerWebserviceObject::fromName($adb, $ownerType);
             $row[$field] = vtws_getId($webserviceObject->getEntityId(), $row[$field]);
         }
     }
     return $row;
 }
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
 public function process()
 {
     $variableList = $this->getTemplateVariableListForModule($this->module);
     $handler = vtws_getModuleHandlerFromName($this->module, $this->user);
     $meta = $handler->getMeta();
     $referenceFields = $meta->getReferenceFieldDetails();
     $fieldColumnMapping = $meta->getFieldColumnMapping();
     $columnTableMapping = $meta->getColumnTableMapping();
     $tableList = array();
     $columnList = array();
     $allColumnList = $meta->getUserAccessibleColumns();
     if (count($variableList) > 0) {
         foreach ($variableList as $column) {
             if (in_array($column, $allColumnList)) {
                 $columnList[] = $column;
             }
         }
         foreach ($columnList as $column) {
             if (!empty($columnTableMapping[$column])) {
                 $tableList[$columnTableMapping[$column]] = '';
             }
         }
         $tableList = array_keys($tableList);
         $defaultTableList = $meta->getEntityDefaultTableList();
         foreach ($defaultTableList as $defaultTable) {
             if (!in_array($defaultTable, $tableList)) {
                 $tableList[] = $defaultTable;
             }
         }
         // right now this is will be limited to module type, entities.
         // need to extend it to non-module entities when we have a reliable way of getting
         // record type from the given record id. non webservice id.
         // can extend to non-module entity without many changes as long as the reference field
         // refers to one type of entity, either module entities or non-module entities.
         if (count($tableList) > 0) {
             $sql = 'select ' . implode(', ', $columnList) . ' from ' . $tableList[0];
             $moduleTableIndexList = $meta->getEntityTableIndexList();
             foreach ($tableList as $index => $tableName) {
                 if ($tableName != $tableList[0]) {
                     $sql .= ' INNER JOIN ' . $tableName . ' ON ' . $tableList[0] . '.' . $moduleTableIndexList[$tableList[0]] . '=' . $tableName . '.' . $moduleTableIndexList[$tableName];
                 }
             }
             $sql .= ' WHERE';
             $deleteQuery = $meta->getEntityDeletedQuery();
             if (!empty($deleteQuery)) {
                 $sql .= ' ' . $meta->getEntityDeletedQuery() . ' AND';
             }
             $sql .= ' ' . $tableList[0] . '.' . $moduleTableIndexList[$tableList[0]] . '=?';
             $params = array($this->recordId);
             $db = PearDatabase::getInstance();
             $result = $db->pquery($sql, $params);
             $it = new SqlResultIterator($db, $result);
             //assuming there can only be one row.
             $values = array();
             foreach ($it as $row) {
                 foreach ($columnList as $column) {
                     $values[$column] = $row->get($column);
                 }
             }
             $moduleFields = $meta->getModuleFields();
             foreach ($moduleFields as $fieldName => $webserviceField) {
                 if (isset($values[$fieldColumnMapping[$fieldName]]) && $values[$fieldColumnMapping[$fieldName]] !== null) {
                     if (strcasecmp($webserviceField->getFieldDataType(), 'reference') === 0) {
                         $details = $webserviceField->getReferenceList();
                         if (count($details) == 1) {
                             $referencedObjectHandler = vtws_getModuleHandlerFromName($details[0], $this->user);
                         } else {
                             $type = getSalesEntityType($values[$fieldColumnMapping[$fieldName]]);
                             $referencedObjectHandler = vtws_getModuleHandlerFromName($type, $this->user);
                         }
                         $referencedObjectMeta = $referencedObjectHandler->getMeta();
                         $values[$fieldColumnMapping[$fieldName]] = $referencedObjectMeta->getName(vtws_getId($referencedObjectMeta->getEntityId(), $values[$fieldColumnMapping[$fieldName]]));
                     } elseif (strcasecmp($webserviceField->getFieldDataType(), 'owner') === 0) {
                         $referencedObjectHandler = vtws_getModuleHandlerFromName(vtws_getOwnerType($values[$fieldColumnMapping[$fieldName]]), $this->user);
                         $referencedObjectMeta = $referencedObjectHandler->getMeta();
                         $values[$fieldColumnMapping[$fieldName]] = $referencedObjectMeta->getName(vtws_getId($referencedObjectMeta->getEntityId(), $values[$fieldColumnMapping[$fieldName]]));
                     } elseif (strcasecmp($webserviceField->getFieldDataType(), 'picklist') === 0) {
                         $values[$fieldColumnMapping[$fieldName]] = getTranslatedString($values[$fieldColumnMapping[$fieldName]], $this->module);
                     } elseif (strcasecmp($webserviceField->getFieldDataType(), 'datetime') === 0) {
                         $values[$fieldColumnMapping[$fieldName]] = $values[$fieldColumnMapping[$fieldName]] . ' ' . DateTimeField::getDBTimeZone();
                     }
                 }
             }
             foreach ($columnList as $column) {
                 $needle = '$' . strtolower($this->module) . "-{$column}\$";
                 $this->processedDescription = str_replace($needle, $values[$column], $this->processedDescription);
             }
         }
     }
     $this->processed = true;
 }
Exemplo n.º 7
0
 public function process($params)
 {
     $module = $this->module;
     $recordId = $this->recordId;
     $variableList = $this->getTemplateVariableListForModule($module);
     $handler = vtws_getModuleHandlerFromName($module, $this->user);
     $meta = $handler->getMeta();
     $referenceFields = $meta->getReferenceFieldDetails();
     $fieldColumnMapping = $meta->getFieldColumnMapping();
     $columnTableMapping = $meta->getColumnTableMapping();
     if ($this->isProcessingReferenceField($params)) {
         $parentFieldColumnMapping = $meta->getFieldColumnMapping();
         $module = $params['referencedMeta']->getEntityName();
         if ($this->processedmodules[$module] || !$this->isModuleActive($module)) {
             return;
         }
         $recordId = $params['id'];
         $meta = $params['referencedMeta'];
         $referenceFields = $meta->getReferenceFieldDetails();
         $fieldColumnMapping = $meta->getFieldColumnMapping();
         $columnTableMapping = $meta->getColumnTableMapping();
         $referenceColumn = $parentFieldColumnMapping[$params['field']];
         $variableList = $this->referencedFields[$referenceColumn];
     }
     $tableList = array();
     $columnList = array();
     $allColumnList = $meta->getUserAccessibleColumns();
     $fieldList = array();
     if (count($variableList) > 0) {
         foreach ($variableList as $column) {
             if (in_array($column, $allColumnList)) {
                 $fieldList[] = array_search($column, $fieldColumnMapping);
                 $columnList[] = $column;
             }
         }
         foreach ($fieldList as $field) {
             if (!empty($columnTableMapping[$fieldColumnMapping[$field]])) {
                 $tableList[$columnTableMapping[$fieldColumnMapping[$field]]] = '';
             }
         }
         $tableList = array_keys($tableList);
         $defaultTableList = $meta->getEntityDefaultTableList();
         foreach ($defaultTableList as $defaultTable) {
             if (!in_array($defaultTable, $tableList)) {
                 $tableList[] = $defaultTable;
             }
         }
         if (count($tableList) > 0 && count($columnList) > 0) {
             $sql = 'select ' . implode(', ', $columnList) . ' from ' . $tableList[0];
             $moduleTableIndexList = $meta->getEntityTableIndexList();
             foreach ($tableList as $index => $tableName) {
                 if ($tableName != $tableList[0]) {
                     $sql .= ' INNER JOIN ' . $tableName . ' ON ' . $tableList[0] . '.' . $moduleTableIndexList[$tableList[0]] . '=' . $tableName . '.' . $moduleTableIndexList[$tableName];
                 }
             }
             //If module is Leads and if you are not selected any leads fields then query failure is happening.
             //By default we are checking where condition on base table.
             if ($module == 'Leads' && !in_array('vtiger_leaddetails', $tableList)) {
                 $sql .= ' INNER JOIN vtiger_leaddetails ON vtiger_leaddetails.leadid = vtiger_crmentity.crmid';
             }
             $sql .= ' WHERE';
             $deleteQuery = $meta->getEntityDeletedQuery();
             if (!empty($deleteQuery)) {
                 $sql .= ' ' . $meta->getEntityDeletedQuery() . ' AND';
             }
             $sql .= ' ' . $tableList[0] . '.' . $moduleTableIndexList[$tableList[0]] . '=?';
             $sqlparams = array($recordId);
             $db = PearDatabase::getInstance();
             $result = $db->pquery($sql, $sqlparams);
             $it = new SqlResultIterator($db, $result);
             //assuming there can only be one row.
             $values = array();
             foreach ($it as $row) {
                 foreach ($fieldList as $field) {
                     $values[$field] = $row->get($fieldColumnMapping[$field]);
                 }
             }
             $moduleFields = $meta->getModuleFields();
             foreach ($moduleFields as $fieldName => $webserviceField) {
                 $presence = $webserviceField->getPresence();
                 if (!in_array($presence, array(0, 2))) {
                     continue;
                 }
                 if (isset($values[$fieldName]) && $values[$fieldName] !== null) {
                     if (strcasecmp($webserviceField->getFieldDataType(), 'reference') === 0) {
                         $details = $webserviceField->getReferenceList();
                         if (count($details) == 1) {
                             $referencedObjectHandler = vtws_getModuleHandlerFromName($details[0], $this->user);
                         } else {
                             $type = getSalesEntityType($values[$fieldName]);
                             $referencedObjectHandler = vtws_getModuleHandlerFromName($type, $this->user);
                         }
                         $referencedObjectMeta = $referencedObjectHandler->getMeta();
                         if (!$this->isProcessingReferenceField($params) && !empty($values[$fieldName])) {
                             $this->process(array('parentMeta' => $meta, 'referencedMeta' => $referencedObjectMeta, 'field' => $fieldName, 'id' => $values[$fieldName]));
                         }
                         $values[$fieldName] = $referencedObjectMeta->getName(vtws_getId($referencedObjectMeta->getEntityId(), $values[$fieldName]));
                     } elseif (strcasecmp($webserviceField->getFieldDataType(), 'owner') === 0) {
                         $referencedObjectHandler = vtws_getModuleHandlerFromName(vtws_getOwnerType($values[$fieldName]), $this->user);
                         $referencedObjectMeta = $referencedObjectHandler->getMeta();
                         /*
                          * operation supported for format $module-parentcolumn:childcolumn$
                          */
                         if (in_array($fieldColumnMapping[$fieldName], array_keys($this->referencedFields))) {
                             $this->process(array('parentMeta' => $meta, 'referencedMeta' => $referencedObjectMeta, 'field' => $fieldName, 'id' => $values[$fieldName], 'owner' => true));
                         }
                         $values[$fieldName] = $referencedObjectMeta->getName(vtws_getId($referencedObjectMeta->getEntityId(), $values[$fieldName]));
                     } elseif (strcasecmp($webserviceField->getFieldDataType(), 'picklist') === 0) {
                         $values[$fieldName] = getTranslatedString($values[$fieldName], $module);
                     } elseif (strcasecmp($fieldName, 'salutationtype') === 0 && $webserviceField->getUIType() == '55') {
                         $values[$fieldName] = getTranslatedString($values[$fieldName], $module);
                     } elseif (strcasecmp($webserviceField->getFieldDataType(), 'datetime') === 0) {
                         $values[$fieldName] = $values[$fieldName] . ' ' . DateTimeField::getDBTimeZone();
                     }
                 }
             }
             if (!$this->isProcessingReferenceField($params)) {
                 foreach ($columnList as $column) {
                     $needle = '$' . strtolower($this->module) . "-{$column}\$";
                     $this->processedDescription = str_replace($needle, $values[array_search($column, $fieldColumnMapping)], $this->processedDescription);
                 }
                 // Is process Description will send false even that module don't have reference record set
                 $this->processedDescription = preg_replace("/\\\$(?:[a-zA-Z0-9]+)-(?:[a-zA-Z0-9]+)(?:_[a-zA-Z0-9]+)?(?::[a-zA-Z0-9]+)(?:[a-zA-Z0-9]+)?(?:_[a-zA-Z0-9]+)?\\\$/", '', $this->processedDescription);
             } else {
                 foreach ($columnList as $column) {
                     $needle = '$' . strtolower($this->module) . '-' . $parentFieldColumnMapping[$params['field']] . ':' . $column . '$';
                     $this->processedDescription = str_replace($needle, $values[array_search($column, $fieldColumnMapping)], $this->processedDescription);
                 }
                 if (!$params['owner']) {
                     $this->processedmodules[$module] = true;
                 }
             }
         }
     }
     $this->processed = true;
 }
Exemplo n.º 8
0
    public function process()
    {
        global $site_URL;
        $imagefound = false;
        $variableList = $this->getTemplateVariableListForModule($this->module);
        $handler = vtws_getModuleHandlerFromName($this->module, $this->user);
        $meta = $handler->getMeta();
        $referenceFields = $meta->getReferenceFieldDetails();
        $fieldColumnMapping = $meta->getFieldColumnMapping();
        $columnTableMapping = $meta->getColumnTableMapping();
        $tableList = array();
        $columnList = array();
        $columnList_full = array();
        $allColumnList = $meta->getUserAccessibleColumns();
        if (count($variableList) > 0) {
            foreach ($variableList as $column) {
                if (in_array($column, $allColumnList)) {
                    $columnList[] = $column;
                    $columnList_full[] = $columnTableMapping[$column] . '.' . $column;
                }
            }
            foreach ($columnList as $column) {
                if (!empty($columnTableMapping[$column])) {
                    $tableList[$columnTableMapping[$column]] = '';
                }
            }
            $tableList = array_keys($tableList);
            $defaultTableList = $meta->getEntityDefaultTableList();
            $tableList = array_merge($tableList, $defaultTableList);
            $leadtables = array('vtiger_leadsubdetails', 'vtiger_leadaddress', 'vtiger_leadscf');
            $leadmerge = array_intersect($tableList, $leadtables);
            if (count($leadmerge) > 0 and !in_array('vtiger_leaddetails', $tableList)) {
                // we need this one because the where condition for Leads uses the converted column from the main table
                $tableList[] = 'vtiger_leaddetails';
            }
            // right now this is will be limited to module type, entities.
            // need to extend it to non-module entities when we have a reliable way of getting
            // record type from the given record id. non webservice id.
            // can extend to non-module entity without many changes as long as the reference field
            // refers to one type of entity, either module entities or non-module entities.
            if (count($tableList) > 0) {
                $sql = 'select ' . implode(', ', $columnList_full) . ' from ' . $tableList[0];
                $moduleTableIndexList = $meta->getEntityTableIndexList();
                foreach ($tableList as $index => $tableName) {
                    if ($tableName != $tableList[0]) {
                        $sql .= ' INNER JOIN ' . $tableName . ' ON ' . $tableList[0] . '.' . $moduleTableIndexList[$tableList[0]] . '=' . $tableName . '.' . $moduleTableIndexList[$tableName];
                    }
                }
                $sql .= ' WHERE';
                $deleteQuery = $meta->getEntityDeletedQuery();
                if (!empty($deleteQuery)) {
                    $sql .= " {$deleteQuery} AND";
                }
                $sql .= ' ' . $tableList[0] . '.' . $moduleTableIndexList[$tableList[0]] . '=?';
                $params = array($this->recordId);
                $db = PearDatabase::getInstance();
                $result = $db->pquery($sql, $params);
                $it = new SqlResultIterator($db, $result);
                //assuming there can only be one row.
                $values = array();
                foreach ($it as $row) {
                    foreach ($columnList as $column) {
                        $values[$column] = $row->get($column);
                    }
                }
                $moduleFields = $meta->getModuleFields();
                foreach ($moduleFields as $fieldName => $webserviceField) {
                    if (isset($values[$fieldColumnMapping[$fieldName]]) && $values[$fieldColumnMapping[$fieldName]] !== null) {
                        $fieldtype = $webserviceField->getFieldDataType();
                        if (strcasecmp($fieldtype, 'reference') === 0) {
                            $details = $webserviceField->getReferenceList();
                            if (count($details) == 1) {
                                $referencedObjectHandler = vtws_getModuleHandlerFromName($details[0], $this->user);
                            } else {
                                $type = getSalesEntityType($values[$fieldColumnMapping[$fieldName]]);
                                $referencedObjectHandler = vtws_getModuleHandlerFromName($type, $this->user);
                            }
                            $referencedObjectMeta = $referencedObjectHandler->getMeta();
                            $values[$fieldColumnMapping[$fieldName]] = $referencedObjectMeta->getName(vtws_getId($referencedObjectMeta->getEntityId(), $values[$fieldColumnMapping[$fieldName]]));
                        } elseif (strcasecmp($fieldtype, 'owner') === 0) {
                            $referencedObjectHandler = vtws_getModuleHandlerFromName(vtws_getOwnerType($values[$fieldColumnMapping[$fieldName]]), $this->user);
                            $referencedObjectMeta = $referencedObjectHandler->getMeta();
                            $values[$fieldColumnMapping[$fieldName]] = $referencedObjectMeta->getName(vtws_getId($referencedObjectMeta->getEntityId(), $values[$fieldColumnMapping[$fieldName]]));
                        } elseif (strcasecmp($fieldtype, 'picklist') === 0 or $fieldName == 'salutationtype') {
                            $values[$fieldColumnMapping[$fieldName]] = getTranslatedString($values[$fieldColumnMapping[$fieldName]], $this->module);
                        } elseif (strcasecmp($fieldtype, 'datetime') === 0) {
                            $values[$fieldColumnMapping[$fieldName]] = $values[$fieldColumnMapping[$fieldName]] . ' ' . DateTimeField::getDBTimeZone();
                        } elseif (strcasecmp($fieldtype, 'currency') === 0 or strcasecmp($fieldtype, 'double') === 0) {
                            $currencyField = new CurrencyField($values[$fieldColumnMapping[$fieldName]]);
                            $values[$fieldColumnMapping[$fieldName]] = $currencyField->getDisplayValue(null, true);
                        } elseif ($webserviceField->getUIType() == 69) {
                            $query = 'select vtiger_attachments.name, vtiger_attachments.type, vtiger_attachments.attachmentsid, vtiger_attachments.path
									from vtiger_attachments
									inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_attachments.attachmentsid
									inner join vtiger_seattachmentsrel on vtiger_attachments.attachmentsid=vtiger_seattachmentsrel.attachmentsid
									where (vtiger_crmentity.setype LIKE "%Image" or vtiger_crmentity.setype LIKE "%Attachment")
									  and deleted=0 and vtiger_seattachmentsrel.crmid=?';
                            $params = array($this->recordId);
                            if (!empty($values[$fieldColumnMapping[$fieldName]])) {
                                $query .= ' and vtiger_attachments.name = ?';
                                $params[] = $values[$fieldColumnMapping[$fieldName]];
                            }
                            $result_image = $db->pquery($query, $params);
                            if ($db->num_rows($result_image) > 0) {
                                $img = $db->fetch_array($result_image);
                                $fullpath = $site_URL . '/' . $img['path'] . $img['attachmentsid'] . '_' . $img['name'];
                                $values[$fieldColumnMapping[$fieldName] . '_fullpath'] = $fullpath;
                                $values[$fieldColumnMapping[$fieldName]] = $img['name'];
                                $imagefound = true;
                            }
                        }
                    }
                }
                foreach ($columnList as $column) {
                    if ($imagefound) {
                        $needle = '$' . strtolower($this->module) . "-{$column}" . '_fullpath$';
                        $this->processedDescription = str_replace($needle, $values[$column . '_fullpath'], $this->processedDescription);
                    }
                    $needle = '$' . strtolower($this->module) . "-{$column}\$";
                    $this->processedDescription = str_replace($needle, $values[$column], $this->processedDescription);
                }
            }
        }
        $this->processed = true;
    }
Exemplo n.º 9
0
 public function process(Vtiger_Request $request)
 {
     $recordId = $request->get('record');
     $modules = $request->get('modules');
     $assignId = $request->get('assigned_user_id');
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $entityValues = array();
     $entityValues['transferRelatedRecordsTo'] = $request->get('transferModule');
     $entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType($assignId), $assignId);
     $entityValues['leadId'] = vtws_getWebserviceEntityId($request->getModule(), $recordId);
     $createAlways = Vtiger_Processes_Model::getConfig('marketing', 'conversion', 'create_always');
     $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $request->getModule());
     $convertLeadFields = $recordModel->getConvertLeadFields();
     $availableModules = array('Accounts', 'Contacts', 'Potentials');
     foreach ($availableModules as $module) {
         if (vtlib_isModuleActive($module) && in_array($module, $modules)) {
             $entityValues['entities'][$module]['create'] = true;
             $entityValues['entities'][$module]['name'] = $module;
             foreach ($convertLeadFields[$module] as $fieldModel) {
                 $fieldName = $fieldModel->getName();
                 $fieldValue = $request->get($fieldName);
                 //Potential Amount Field value converting into DB format
                 if ($fieldModel->getFieldDataType() === 'currency') {
                     $fieldValue = Vtiger_Currency_UIType::convertToDBFormat($fieldValue);
                 } elseif ($fieldModel->getFieldDataType() === 'date') {
                     $fieldValue = DateTimeField::convertToDBFormat($fieldValue);
                 } elseif ($fieldModel->getFieldDataType() === 'reference' && $fieldValue) {
                     $ids = vtws_getIdComponents($fieldValue);
                     if (count($ids) === 1) {
                         $fieldValue = vtws_getWebserviceEntityId(getSalesEntityType($fieldValue), $fieldValue);
                     }
                 }
                 $entityValues['entities'][$module][$fieldName] = $fieldValue;
             }
         }
     }
     try {
         $results = true;
         if ($createAlways === true || $createAlways === 'true') {
             $leadModel = Vtiger_Module_Model::getCleanInstance($request->getModule());
             $results = $leadModel->searchAccountsToConvert($recordModel);
             $entityValues['entities']['Accounts']['convert_to_id'] = $results;
         }
         if (!$results) {
             $message = vtranslate('LBL_TOO_MANY_ACCOUNTS_TO_CONVERT', $request->getModule(), '');
             if ($currentUser->isAdminUser()) {
                 $message = vtranslate('LBL_TOO_MANY_ACCOUNTS_TO_CONVERT', $request->getModule(), '<a href="index.php?module=MarketingProcesses&view=Index&parent=Settings"><span class="glyphicon glyphicon-folder-open"></span></a>');
             }
             $this->showError($request, '', $message);
             exit;
         }
     } catch (Exception $e) {
         $this->showError($request, $e);
         exit;
     }
     try {
         $result = vtws_convertlead($entityValues, $currentUser);
     } catch (Exception $e) {
         $this->showError($request, $e);
         exit;
     }
     if (!empty($result['Accounts'])) {
         $accountIdComponents = vtws_getIdComponents($result['Accounts']);
         $accountId = $accountIdComponents[1];
     }
     if (!empty($result['Contacts'])) {
         $contactIdComponents = vtws_getIdComponents($result['Contacts']);
         $contactId = $contactIdComponents[1];
     }
     if (!empty($accountId)) {
         ModTracker_Record_Model::addConvertToAccountRelation('Accounts', $accountId, $assignId);
         header("Location: index.php?view=Detail&module=Accounts&record={$accountId}");
     } elseif (!empty($contactId)) {
         header("Location: index.php?view=Detail&module=Contacts&record={$contactId}");
     } else {
         $this->showError($request);
         exit;
     }
 }
Exemplo n.º 10
0
 /**
  * Create new Email record (and link to given record) including attachements
  */
 function __CreateNewEmail($mailrecord, $module, $linkfocus)
 {
     global $current_user, $adb;
     if (!$current_user) {
         $current_user = Users::getActiveAdminUser();
     }
     $assignedToId = $linkfocus->column_fields['assigned_user_id'];
     if (vtws_getOwnerType($assignedToId) == 'Groups') {
         $assignedToId = Users::getActiveAdminId();
     }
     $focus = new Emails();
     $focus->column_fields['parent_type'] = $module;
     $focus->column_fields['activitytype'] = 'Emails';
     $focus->column_fields['parent_id'] = "{$linkfocus->id}@-1|";
     $focus->column_fields['subject'] = $mailrecord->_subject;
     $focus->column_fields['description'] = $mailrecord->getBodyHTML();
     $focus->column_fields['assigned_user_id'] = $assignedToId;
     $focus->column_fields["date_start"] = date('Y-m-d', $mailrecord->_date);
     $focus->column_fields["time_start"] = gmdate("H:i:s");
     $focus->column_fields["email_flag"] = 'MAILSCANNER';
     $from = $mailrecord->_from[0];
     $to = $mailrecord->_to[0];
     $cc = !empty($mailrecord->_cc) ? implode(',', $mailrecord->_cc) : '';
     $bcc = !empty($mailrecord->_bcc) ? implode(',', $mailrecord->_bcc) : '';
     $flag = '';
     // 'SENT'/'SAVED'
     //emails field were restructured and to,bcc and cc field are JSON arrays
     $focus->column_fields['from_email'] = $from;
     $focus->column_fields['saved_toid'] = $to;
     $focus->column_fields['ccmail'] = $cc;
     $focus->column_fields['bccmail'] = $bcc;
     $focus->save('Emails');
     $emailid = $focus->id;
     $this->log("Created [{$focus->id}]: {$mailrecord->_subject} linked it to " . $linkfocus->id);
     // TODO: Handle attachments of the mail (inline/file)
     $this->__SaveAttachements($mailrecord, 'Emails', $focus);
     return $emailid;
 }
Exemplo n.º 11
-9
 function captureNow($request)
 {
     $currentLanguage = Vtiger_Language_Handler::getLanguage();
     $moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage);
     vglobal('app_strings', $moduleLanguageStrings['languageStrings']);
     $returnURL = false;
     try {
         if (!vtlib_isModuleActive('Webforms')) {
             throw new Exception('webforms is not active');
         }
         $webform = Webforms_Model::retrieveWithPublicId(vtlib_purify($request['publicid']));
         if (empty($webform)) {
             throw new Exception("Webform not found.");
         }
         $returnURL = $webform->getReturnUrl();
         $roundrobin = $webform->getRoundrobin();
         // Retrieve user information
         $user = CRMEntity::getInstance('Users');
         $user->id = $user->getActiveAdminId();
         $user->retrieve_entity_info($user->id, 'Users');
         // Prepare the parametets
         $parameters = array();
         $webformFields = $webform->getFields();
         foreach ($webformFields as $webformField) {
             if ($webformField->getDefaultValue() != null) {
                 $parameters[$webformField->getFieldName()] = decode_html($webformField->getDefaultValue());
             } else {
                 $webformNeutralizedField = html_entity_decode($webformField->getNeutralizedField(), ENT_COMPAT, "UTF-8");
                 if (is_array(vtlib_purify($request[$webformNeutralizedField]))) {
                     $fieldData = implode(" |##| ", vtlib_purify($request[$webformNeutralizedField]));
                 } else {
                     $fieldData = vtlib_purify($request[$webformNeutralizedField]);
                     $fieldData = decode_html($fieldData);
                 }
                 $parameters[$webformField->getFieldName()] = stripslashes($fieldData);
             }
             if ($webformField->getRequired()) {
                 if (!isset($parameters[$webformField->getFieldName()])) {
                     throw new Exception("Required fields not filled");
                 }
             }
         }
         if ($roundrobin) {
             $ownerId = $webform->getRoundrobinOwnerId();
             $ownerType = vtws_getOwnerType($ownerId);
             $parameters['assigned_user_id'] = vtws_getWebserviceEntityId($ownerType, $ownerId);
         } else {
             $ownerId = $webform->getOwnerId();
             $ownerType = vtws_getOwnerType($ownerId);
             $parameters['assigned_user_id'] = vtws_getWebserviceEntityId($ownerType, $ownerId);
         }
         // Create the record
         $record = vtws_create($webform->getTargetModule(), $parameters, $user);
         $this->sendResponse($returnURL, 'ok');
         return;
     } catch (Exception $e) {
         $this->sendResponse($returnURL, false, $e->getMessage());
         return;
     }
 }