Esempio n. 1
0
 /**
  * Function to search emails for send email
  * @param <String> $searchValue
  * @return <Array> Result of searched emails
  */
 public function searchEmails($searchValue)
 {
     $emailsResult = array();
     $db = PearDatabase::getInstance();
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $emailSupportedModulesList = $this->getEmailRelatedModules();
     foreach ($emailSupportedModulesList as $moduleName) {
         $searchFields = array();
         $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
         $emailFieldModels = $moduleModel->getFieldsByType('email');
         foreach ($emailFieldModels as $fieldName => $fieldModel) {
             if ($fieldModel->isViewable()) {
                 $searchFields[] = $fieldName;
             }
         }
         $emailFields = $searchFields;
         $nameFields = $moduleModel->getNameFields();
         foreach ($nameFields as $fieldName) {
             $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $moduleModel);
             if ($fieldModel->isViewable()) {
                 $searchFields[] = $fieldName;
             }
         }
         if ($emailFields) {
             $moduleInstance = CRMEntity::getInstance($moduleName);
             $queryGenerator = new QueryGenerator($moduleName, $currentUserModel);
             $listFields = $searchFields;
             $listFields[] = 'id';
             $queryGenerator->setFields($listFields);
             //Opensource fix for showing up deleted records on email search
             $queryGenerator->startGroup("");
             foreach ($searchFields as $key => $emailField) {
                 $queryGenerator->addCondition($emailField, trim($searchValue), 'c', 'OR');
             }
             $queryGenerator->endGroup();
             $result = $db->pquery($queryGenerator->getQuery(), array());
             $numOfRows = $db->num_rows($result);
             for ($i = 0; $i < $numOfRows; $i++) {
                 $row = $db->query_result_rowdata($result, $i);
                 foreach ($emailFields as $emailField) {
                     $emailFieldValue = $row[$emailField];
                     if ($emailFieldValue) {
                         $recordLabel = getEntityFieldNameDisplay($moduleName, $nameFields, $row);
                         if (strpos($emailFieldValue, $searchValue) !== false || strpos($recordLabel, $searchValue) !== false) {
                             $emailsResult[vtranslate($moduleName, $moduleName)][$row[$moduleInstance->table_index]][] = array('value' => $emailFieldValue, 'label' => $recordLabel . ' <b>(' . $emailFieldValue . ')</b>');
                         }
                     }
                 }
             }
         }
     }
     return $emailsResult;
 }
/**
 * 	Function to Check whether the User is allowed to delete a particular record from listview of each module using
 * 	mass delete button.
 * 	@param string $module -- module name
 * 	@param array $ids_list -- Record id
 * 	Returns the Record Names of each module that is not permitted to delete
 * */
function getEntityName($module, $ids_list)
{
    global $adb, $log;
    $log->debug("Entering getEntityName(" . $module . ") method ...");
    if ($module == 'Events') {
        $module = 'Calendar';
    }
    if ($module != '') {
        if (count($ids_list) <= 0) {
            return array();
        }
        $entityDisplay = array();
        $entity_field_info = getEntityFieldNames($module);
        $tableName = $entity_field_info['tablename'];
        $fieldsName = $entity_field_info['fieldname'];
        $moduleName = $entity_field_info['modulename'];
        $entityIdField = $entity_field_info['entityidfield'];
        $entity_FieldValue = getEntityFieldValues($entity_field_info, $ids_list);
        foreach ($entity_FieldValue as $key => $entityInfo) {
            foreach ($entityInfo as $key => $entityName) {
                $fieldValues = $entityName;
                $entityDisplay[$key] = getEntityFieldNameDisplay($module, $fieldsName, $fieldValues);
            }
        }
        return $entityDisplay;
    }
    $log->debug("Exiting getEntityName method ...");
}