Exemple #1
0
 function fileDisplay()
 {
     // Display evidence file
     $postParams = $_POST;
     $fileID = CRM_Core_BAO_File::getEntityFile($postParams['entityTable'], $postParams['entityID']);
     if ($fileID) {
         foreach ($fileID as $k => $v) {
             $fileType = $v['mime_type'];
             $fid = $v['fileID'];
             $eid = $postParams['entityID'];
             if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') {
                 list($path) = CRM_Core_BAO_File::path($fid, $eid, NULL, NULL);
                 list($imageWidth, $imageHeight) = getimagesize($path);
                 list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}", FALSE, NULL, TRUE, TRUE);
                 $file_url = "\n              <a href=\"{$url}\" class='crm-image-popup'>\n              <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n              </a>";
                 // for non image files
             } else {
                 $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fid, 'uri');
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fid}&eid={$eid}");
                 $file_url = "<a href=\"{$url}\">{$uri}</a>";
             }
             if (isset($fid)) {
                 $deleteurl = "<div class=file-delete><a class='action-item crm-hover-button' href='javascript:void(0)' id=file_{$fid}>Delete Attached File</a></div>";
                 echo "<div id='del_{$fid}'>{$file_url}{$deleteurl}</div>";
             }
         }
     }
     CRM_Utils_System::civiExit();
 }
Exemple #2
0
 public function run()
 {
     $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this);
     list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, NULL, $quest);
     if (!$path) {
         CRM_Core_Error::statusBounce('Could not retrieve the file');
     }
     $buffer = file_get_contents($path);
     if (!$buffer) {
         CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
     }
     if ($action & CRM_Core_Action::DELETE) {
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
             CRM_Core_BAO_File::deleteFileReferences($id, $eid, $fid);
             CRM_Core_Session::setStatus(ts('The attached file has been deleted.'), ts('Complete'), 'success');
             $session = CRM_Core_Session::singleton();
             $toUrl = $session->popUserContext();
             CRM_Utils_System::redirect($toUrl);
         }
     } else {
         CRM_Utils_System::download(CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer);
     }
 }
Exemple #3
0
 function run()
 {
     require_once 'CRM/Utils/Request.php';
     require_once 'CRM/Core/DAO.php';
     $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, true);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, false);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
     $quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this);
     require_once 'CRM/Core/BAO/File.php';
     list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, null, $quest);
     if (!$path) {
         CRM_Core_Error::statusBounce('Could not retrieve the file');
     }
     $buffer = file_get_contents($path);
     if (!$buffer) {
         CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
     }
     if ($action & CRM_Core_Action::DELETE) {
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
             CRM_Core_BAO_File::delete($id, $eid, $fid);
             CRM_Core_Session::setStatus(ts('The attached file has been deleted.'));
             $session = CRM_Core_Session::singleton();
             $toUrl = $session->popUserContext();
             CRM_Utils_System::redirect($toUrl);
         } else {
             $wrapper = new CRM_Utils_Wrapper();
             return $wrapper->run('CRM_Custom_Form_DeleteFile', ts('Domain Information Page'), null);
         }
     } else {
         require_once 'CRM/Utils/File.php';
         CRM_Utils_System::download(CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer);
     }
 }
 /**
  * Copy custom fields and attachments from an existing activity to another.
  *
  * @see CRM_Case_Page_AJAX::_convertToCaseActivity()
  *
  * @param array $params
  */
 public static function copyExtendedActivityData($params)
 {
     // attach custom data to the new activity
     $customParams = $htmlType = array();
     $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($params['activityID'], 'Activity');
     if (!empty($customValues)) {
         $fieldIds = implode(', ', array_keys($customValues));
         $sql = "SELECT id FROM civicrm_custom_field WHERE html_type = 'File' AND id IN ( {$fieldIds} )";
         $result = CRM_Core_DAO::executeQuery($sql);
         while ($result->fetch()) {
             $htmlType[] = $result->id;
         }
         foreach ($customValues as $key => $value) {
             if ($value !== NULL) {
                 // CRM-10542
                 if (in_array($key, $htmlType)) {
                     $fileValues = CRM_Core_BAO_File::path($value, $params['activityID']);
                     $customParams["custom_{$key}_-1"] = array('name' => $fileValues[0], 'path' => $fileValues[1]);
                 } else {
                     $customParams["custom_{$key}_-1"] = $value;
                 }
             }
         }
         CRM_Core_BAO_CustomValueTable::postProcess($customParams, 'civicrm_activity', $params['mainActivityId'], 'Activity');
     }
     // copy activity attachments ( if any )
     CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $params['activityID'], 'civicrm_activity', $params['mainActivityId']);
 }
 /**
  * Build the entity-specific custom data into the group tree on a per-field basis
  *
  * @param object $dao
  *   Object representing the custom field to be populated into the groupTree.
  * @param array $groupTree
  *   (reference) the group tree being build.
  * @param string $table
  *   Table name.
  * @param int $groupID
  *   Custom group ID.
  * @param int $fieldID
  *   Custom field ID.
  */
 public static function buildCustomFieldData($dao, &$groupTree, $table, $groupID, $fieldID)
 {
     $column = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
     $idName = "{$table}_id";
     $fieldName = "{$table}_{$column}";
     $dataType = $groupTree[$groupID]['fields'][$fieldID]['data_type'];
     if ($dataType == 'File') {
         if (isset($dao->{$fieldName})) {
             $config = CRM_Core_Config::singleton();
             $fileDAO = new CRM_Core_DAO_File();
             $fileDAO->id = $dao->{$fieldName};
             if ($fileDAO->find(TRUE)) {
                 $entityIDName = "{$table}_entity_id";
                 $customValue['id'] = $dao->{$idName};
                 $customValue['data'] = $fileDAO->uri;
                 $customValue['fid'] = $fileDAO->id;
                 $customValue['fileURL'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileDAO->id}&eid={$dao->{$entityIDName}}");
                 $customValue['displayURL'] = NULL;
                 $deleteExtra = ts('Are you sure you want to delete attached file.');
                 $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Attached File'), 'url' => 'civicrm/file', 'qs' => 'reset=1&id=%%id%%&eid=%%eid%%&fid=%%fid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"'));
                 $customValue['deleteURL'] = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $fileDAO->id, 'eid' => $dao->{$entityIDName}, 'fid' => $fieldID), ts('more'), FALSE, 'file.manage.delete', 'File', $fileDAO->id);
                 $customValue['deleteURLArgs'] = CRM_Core_BAO_File::deleteURLArgs($table, $dao->{$entityIDName}, $fileDAO->id);
                 $customValue['fileName'] = CRM_Utils_File::cleanFileName(basename($fileDAO->uri));
                 if ($fileDAO->mime_type == "image/jpeg" || $fileDAO->mime_type == "image/pjpeg" || $fileDAO->mime_type == "image/gif" || $fileDAO->mime_type == "image/x-png" || $fileDAO->mime_type == "image/png") {
                     $customValue['displayURL'] = $customValue['fileURL'];
                     $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileDAO->id, 'entity_id', 'file_id');
                     $customValue['imageURL'] = str_replace('persist/contribute', 'custom', $config->imageUploadURL) . $fileDAO->uri;
                     list($path) = CRM_Core_BAO_File::path($fileDAO->id, $entityId, NULL, NULL);
                     if ($path && file_exists($path)) {
                         list($imageWidth, $imageHeight) = getimagesize($path);
                         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
                         $customValue['imageThumbWidth'] = $imageThumbWidth;
                         $customValue['imageThumbHeight'] = $imageThumbHeight;
                     }
                 }
             }
         } else {
             $customValue = array('id' => $dao->{$idName}, 'data' => '');
         }
     } else {
         $customValue = array('id' => $dao->{$idName}, 'data' => $dao->{$fieldName});
     }
     if (!array_key_exists('customValue', $groupTree[$groupID]['fields'][$fieldID])) {
         $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array();
     }
     if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) {
         $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(1 => $customValue);
     } else {
         $groupTree[$groupID]['fields'][$fieldID]['customValue'][] = $customValue;
     }
 }
 /**
  * @param int $contactID
  * @param int $cfID
  * @param int $fileID
  * @param bool $absolute
  *
  * @return array
  */
 public static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL)
 {
     if ($contactID) {
         if (!$fileID) {
             $params = array('id' => $cfID);
             $defaults = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
             $columnName = $defaults['column_name'];
             //table name of custom data
             $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $defaults['custom_group_id'], 'table_name', 'id');
             //query to fetch id from civicrm_file
             if ($multiRecordWhereClause) {
                 $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID} AND {$multiRecordWhereClause}";
             } else {
                 $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
             }
             $fileID = CRM_Core_DAO::singleValueQuery($query);
         }
         $result = array();
         if ($fileID) {
             $fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'mime_type', 'id');
             $result['file_id'] = $fileID;
             if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') {
                 $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileID, 'entity_id', 'id');
                 list($path) = CRM_Core_BAO_File::path($fileID, $entityId, NULL, NULL);
                 list($imageWidth, $imageHeight) = getimagesize($path);
                 list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}", $absolute, NULL, TRUE, TRUE);
                 $result['file_url'] = "\n          <a href=\"{$url}\" class='crm-image-popup'>\n          <img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/>\n          </a>";
                 // for non image files
             } else {
                 $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'uri');
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}", $absolute, NULL, TRUE, TRUE);
                 $result['file_url'] = "<a href=\"{$url}\">{$uri}</a>";
             }
         }
         return $result;
     }
 }
 /**
  * Get custom groups/fields for type of entity.
  *
  * An array containing all custom groups and their custom fields is returned.
  *
  * @param string $entityType - of the contact whose contact type is needed
  * @param int    $entityId   - optional - id of entity if we need to populate the tree with custom values. 
  * @param int    $groupId    - optional group id (if we need it for a single group only)
  *                           - if groupId is 0 it gets for inline groups only
  *                           - if groupId is -1 we get for all groups
  *
  * @return array $groupTree  - array consisting of all groups and fields and optionally populated with custom data values.
  *
  * @access public
  *
  * @static
  *
  */
 public static function &getTree($entityType, &$form, $entityID = null, $groupID = null, $subType = null, $subName = null)
 {
     if ($entityID) {
         $entityID = CRM_Utils_Type::escape($entityID, 'Integer');
     }
     require_once 'CRM/Core/Action.php';
     // create a new tree
     $groupTree = array();
     $strSelect = $strFrom = $strWhere = $orderBy = '';
     $tableData = array();
     // using tableData to build the queryString
     $tableData = array('civicrm_custom_field' => array('id', 'label', 'column_name', 'data_type', 'html_type', 'default_value', 'attributes', 'is_required', 'is_view', 'help_pre', 'help_post', 'options_per_line', 'start_date_years', 'end_date_years', 'date_format', 'time_format', 'option_group_id'), 'civicrm_custom_group' => array('id', 'name', 'table_name', 'title', 'help_pre', 'help_post', 'collapse_display', 'is_multiple', 'extends', 'extends_entity_column_id', 'extends_entity_column_value', 'max_multiple'));
     // create select
     $select = array();
     foreach ($tableData as $tableName => $tableColumn) {
         foreach ($tableColumn as $columnName) {
             $alias = $tableName . "_" . $columnName;
             $select[] = "{$tableName}.{$columnName} as {$tableName}_{$columnName}";
         }
     }
     $strSelect = "SELECT " . implode(', ', $select);
     // from, where, order by
     $strFrom = "\nFROM     civicrm_custom_group\nLEFT JOIN civicrm_custom_field ON (civicrm_custom_field.custom_group_id = civicrm_custom_group.id)\n";
     // if entity is either individual, organization or household pls get custom groups for 'contact' too.
     if ($entityType == "Individual" || $entityType == 'Organization' || $entityType == 'Household') {
         $in = "'{$entityType}', 'Contact'";
     } else {
         if (strpos($entityType, "'") !== false) {
             // this allows the calling function to send in multiple entity types
             $in = $entityType;
         } else {
             // quote it
             $in = "'{$entityType}'";
         }
     }
     if ($subType) {
         $subType = CRM_Core_DAO::VALUE_SEPARATOR . trim($subType, CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
         $strWhere = "\nWHERE civicrm_custom_group.is_active = 1 \n  AND civicrm_custom_field.is_active = 1 \n  AND civicrm_custom_group.extends IN ({$in})\n  AND ( civicrm_custom_group.extends_entity_column_value LIKE '%{$subType}%'\n   OR   civicrm_custom_group.extends_entity_column_value IS NULL )\n";
         if ($subName) {
             $strWhere .= " AND civicrm_custom_group.extends_entity_column_id = {$subName} ";
         }
     } else {
         $strWhere = "\nWHERE civicrm_custom_group.is_active = 1 \n  AND civicrm_custom_field.is_active = 1 \n  AND civicrm_custom_group.extends IN ({$in})\n  AND civicrm_custom_group.extends_entity_column_value IS NULL\n";
     }
     $params = array();
     if ($groupID > 0) {
         // since we want a specific group id we add it to the where clause
         $strWhere .= " AND civicrm_custom_group.id = %1";
         $params[1] = array($groupID, 'Integer');
     } else {
         if (!$groupID) {
             // since groupID is false we need to show all Inline groups
             $strWhere .= " AND civicrm_custom_group.style = 'Inline'";
         }
     }
     require_once 'CRM/Core/Permission.php';
     // ensure that the user has access to these custom groups
     $strWhere .= " AND " . CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, 'civicrm_custom_group.');
     $orderBy = "\nORDER BY civicrm_custom_group.weight,\n         civicrm_custom_group.title,\n         civicrm_custom_field.weight,\n         civicrm_custom_field.label\n";
     // final query string
     $queryString = "{$strSelect} {$strFrom} {$strWhere} {$orderBy}";
     //crm_core_error::debug('$queryString', $queryString );
     // dummy dao needed
     $crmDAO =& CRM_Core_DAO::executeQuery($queryString, $params);
     $customValueTables = array();
     // process records
     while ($crmDAO->fetch()) {
         // get the id's
         $groupID = $crmDAO->civicrm_custom_group_id;
         $fieldId = $crmDAO->civicrm_custom_field_id;
         // create an array for groups if it does not exist
         if (!array_key_exists($groupID, $groupTree)) {
             $groupTree[$groupID] = array();
             $groupTree[$groupID]['id'] = $groupID;
             // populate the group information
             foreach ($tableData['civicrm_custom_group'] as $fieldName) {
                 $fullFieldName = "civicrm_custom_group_{$fieldName}";
                 if ($fieldName == 'id' || is_null($crmDAO->{$fullFieldName})) {
                     continue;
                 }
                 if ($fieldName == 'extends_entity_column_value' && $subType) {
                     // CRM-5507
                     $groupTree[$groupID]['subtype'] = trim($subType, CRM_Core_DAO::VALUE_SEPARATOR);
                 }
                 $groupTree[$groupID][$fieldName] = $crmDAO->{$fullFieldName};
             }
             $groupTree[$groupID]['fields'] = array();
             $customValueTables[$crmDAO->civicrm_custom_group_table_name] = array();
         }
         // add the fields now (note - the query row will always contain a field)
         // we only reset this once, since multiple values come is as multiple rows
         if (!array_key_exists($fieldId, $groupTree[$groupID]['fields'])) {
             $groupTree[$groupID]['fields'][$fieldId] = array();
         }
         $customValueTables[$crmDAO->civicrm_custom_group_table_name][$crmDAO->civicrm_custom_field_column_name] = 1;
         $groupTree[$groupID]['fields'][$fieldId]['id'] = $fieldId;
         // populate information for a custom field
         foreach ($tableData['civicrm_custom_field'] as $fieldName) {
             $fullFieldName = "civicrm_custom_field_{$fieldName}";
             if ($fieldName == 'id' || is_null($crmDAO->{$fullFieldName})) {
                 continue;
             }
             $groupTree[$groupID]['fields'][$fieldId][$fieldName] = $crmDAO->{$fullFieldName};
         }
     }
     require_once 'CRM/Core/Action.php';
     // now that we have all the groups and fields, lets get the values
     // since we need to know the table and field names
     // add info to groupTree
     if (!empty($customValueTables)) {
         $groupTree['info'] = array('tables' => $customValueTables);
         $select = $from = $where = array();
         foreach ($groupTree['info']['tables'] as $table => $fields) {
             $from[] = $table;
             $select[] = "{$table}.id as {$table}_id";
             $select[] = "{$table}.entity_id as {$table}_entity_id";
             foreach ($fields as $column => $dontCare) {
                 $select[] = "{$table}.{$column} as {$table}_{$column}";
             }
             if ($entityID) {
                 $where[] = "{$table}.entity_id = {$entityID}";
             }
         }
         $groupTree['info']['select'] = $select;
         $groupTree['info']['from'] = $from;
         $groupTree['info']['where'] = null;
         if ($entityID) {
             $groupTree['info']['where'] = $where;
             $select = implode(', ', $select);
             // this is a hack to find a table that has some values for this
             // entityID to make the below LEFT JOIN work (CRM-2518)
             $firstTable = null;
             foreach ($from as $table) {
                 $query = "\nSELECT id\nFROM   {$table}\nWHERE  entity_id = {$entityID}\n";
                 $recordExists = CRM_Core_DAO::singleValueQuery($query);
                 if ($recordExists) {
                     $firstTable = $table;
                     break;
                 }
             }
             if ($firstTable) {
                 $fromSQL = $firstTable;
                 foreach ($from as $table) {
                     if ($table != $firstTable) {
                         $fromSQL .= "\nLEFT JOIN {$table} USING (entity_id)";
                     }
                 }
                 $query = "\nSELECT {$select}\n  FROM {$fromSQL}\n WHERE {$firstTable}.entity_id = {$entityID}\n";
                 $dao = CRM_Core_DAO::executeQuery($query);
                 while ($dao->fetch()) {
                     foreach ($groupTree as $groupID => $group) {
                         if ($groupID === 'info') {
                             continue;
                         }
                         $table = $groupTree[$groupID]['table_name'];
                         foreach ($group['fields'] as $fieldID => $dontCare) {
                             $column = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
                             $idName = "{$table}_id";
                             $fieldName = "{$table}_{$column}";
                             $dataType = $groupTree[$groupID]['fields'][$fieldID]['data_type'];
                             if ($dataType == 'File') {
                                 if (isset($dao->{$fieldName})) {
                                     require_once 'CRM/Core/DAO/File.php';
                                     $config = CRM_Core_Config::singleton();
                                     $fileDAO = new CRM_Core_DAO_File();
                                     $fileDAO->id = $dao->{$fieldName};
                                     if ($fileDAO->find(true)) {
                                         $entityIDName = "{$table}_entity_id";
                                         $customValue['id'] = $dao->{$idName};
                                         $customValue['data'] = $fileDAO->uri;
                                         $customValue['fid'] = $fileDAO->id;
                                         $customValue['fileURL'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileDAO->id}&eid={$dao->{$entityIDName}}");
                                         $customValue['displayURL'] = null;
                                         $deleteExtra = ts('Are you sure you want to delete attached file.');
                                         $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Attached File'), 'url' => 'civicrm/file', 'qs' => 'reset=1&id=%%id%%&eid=%%eid%%&fid=%%fid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&amp;confirmed=1\'; else return false;"'));
                                         $customValue['deleteURL'] = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $fileDAO->id, 'eid' => $dao->{$entityIDName}, 'fid' => $fieldID));
                                         $customValue['fileName'] = CRM_Utils_File::cleanFileName(basename($fileDAO->uri));
                                         if ($fileDAO->mime_type == "image/jpeg" || $fileDAO->mime_type == "image/pjpeg" || $fileDAO->mime_type == "image/gif" || $fileDAO->mime_type == "image/x-png" || $fileDAO->mime_type == "image/png") {
                                             $customValue['displayURL'] = $customValue['fileURL'];
                                             $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileDAO->id, 'entity_id', 'id');
                                             require_once 'CRM/Core/BAO/File.php';
                                             list($path) = CRM_Core_BAO_File::path($fileDAO->id, $entityId, null, null);
                                             list($imageWidth, $imageHeight) = getimagesize($path);
                                             require_once 'CRM/Contact/BAO/Contact.php';
                                             list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
                                             $customValue['imageThumbWidth'] = $imageThumbWidth;
                                             $customValue['imageThumbHeight'] = $imageThumbHeight;
                                         }
                                     }
                                 } else {
                                     $customValue = array('id' => $dao->{$idName}, 'data' => '');
                                 }
                             } else {
                                 $customValue = array('id' => $dao->{$idName}, 'data' => $dao->{$fieldName});
                             }
                             if (!array_key_exists('customValue', $groupTree[$groupID]['fields'][$fieldID])) {
                                 $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array();
                             }
                             if (empty($groupTree[$groupID]['fields'][$fieldID]['customValue'])) {
                                 $groupTree[$groupID]['fields'][$fieldID]['customValue'] = array(1 => $customValue);
                             } else {
                                 $groupTree[$groupID]['fields'][$fieldID]['customValue'][] = $customValue;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $groupTree;
 }
 static function getFileURL($contactID, $cfID, $fileID = NULL)
 {
     if ($contactID) {
         if (!$fileID) {
             $params = array('id' => $cfID);
             $defaults = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
             $columnName = $defaults['column_name'];
             //table name of custom data
             $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $defaults['custom_group_id'], 'table_name', 'id');
             //query to fetch id from civicrm_file
             $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
             $fileID = CRM_Core_DAO::singleValueQuery($query);
         }
         $result = array();
         if ($fileID) {
             $fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'mime_type', 'id');
             $result['file_id'] = $fileID;
             if ($fileType == "image/jpeg" || $fileType == "image/pjpeg" || $fileType == "image/gif" || $fileType == "image/x-png" || $fileType == "image/png") {
                 $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileID, 'entity_id', 'id');
                 require_once 'CRM/Core/BAO/File.php';
                 list($path) = CRM_Core_BAO_File::path($fileID, $entityId, null, null);
                 list($imageWidth, $imageHeight) = getimagesize($path);
                 list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}");
                 $result['file_url'] = "<a href='javascript:imagePopUp(\"{$url}\");'><img src=\"{$url}\" width={$imageThumbWidth} height={$imageThumbHeight}/></a>";
             } else {
                 // for non image files
                 $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'uri');
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}");
                 $result['file_url'] = "<a href=\"{$url}\">{$uri}</a>";
             }
         }
         return $result;
     }
 }
Exemple #9
0
 public static function fileDelete()
 {
     $postParams = $_GET;
     $fileId = $postParams['fileID'];
     $result = 0;
     CRM_Core_BAO_File::deleteEntityFile($postParams['entityTable'], $postParams['entityID'], $fileTypeID = NULL, $fileId);
     list($path) = CRM_Core_BAO_File::path($fileId, $postParams['entityID'], NULL, NULL);
     if ($path === null) {
         $result = 1;
     }
     echo html_entity_decode(stripcslashes(json_encode(array('values' => array(array('result' => $result))), true)));
     CRM_Utils_System::civiExit();
 }
Exemple #10
0
 /**
  * Get file url.
  *
  * @param int $contactID
  * @param int $cfID
  * @param int $fileID
  * @param bool $absolute
  *
  * @param string $multiRecordWhereClause
  *
  * @return array
  */
 public static function getFileURL($contactID, $cfID, $fileID = NULL, $absolute = FALSE, $multiRecordWhereClause = NULL)
 {
     if ($contactID) {
         if (!$fileID) {
             $params = array('id' => $cfID);
             $defaults = array();
             CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
             $columnName = $defaults['column_name'];
             //table name of custom data
             $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $defaults['custom_group_id'], 'table_name', 'id');
             //query to fetch id from civicrm_file
             if ($multiRecordWhereClause) {
                 $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID} AND {$multiRecordWhereClause}";
             } else {
                 $query = "SELECT {$columnName} FROM {$tableName} where entity_id = {$contactID}";
             }
             $fileID = CRM_Core_DAO::singleValueQuery($query);
         }
         $result = array();
         if ($fileID) {
             $fileType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'mime_type', 'id');
             $result['file_id'] = $fileID;
             if ($fileType == 'image/jpeg' || $fileType == 'image/pjpeg' || $fileType == 'image/gif' || $fileType == 'image/x-png' || $fileType == 'image/png') {
                 $entityId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $fileID, 'entity_id', 'id');
                 list($path) = CRM_Core_BAO_File::path($fileID, $entityId, NULL, NULL);
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}", $absolute, NULL, TRUE, TRUE);
                 $result['file_url'] = CRM_Utils_File::getFileURL($path, $fileType, $url);
             } else {
                 $uri = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $fileID, 'uri');
                 $url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileID}&eid={$contactID}", $absolute, NULL, TRUE, TRUE);
                 $result['file_url'] = CRM_Utils_File::getFileURL($uri, $fileType, $url);
             }
         }
         return $result;
     }
 }