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); } }
function run() { $sql = "\nSELECT distinct(g.id), g.*\nFROM civicrm_option_group g,\n civicrm_custom_field f,\n civicrm_custom_group cg\nWHERE f.option_group_id = g.id\nAND f.custom_group_id = cg.id\nAND cg.is_active = 1\n"; $this->fetch('optionGroup', 'CRM_Core_DAO_OptionGroup', $sql, array('id', 'label')); $sql = "\nSELECT v.*\nFROM civicrm_option_value v,\n civicrm_option_group g,\n civicrm_custom_field f,\n civicrm_custom_group cg\nWHERE v.option_group_id = g.id\nAND f.option_group_id = g.id\nAND f.custom_group_id = cg.id\nAND cg.is_active = 1\n"; $this->fetch('optionValue', 'CRM_Core_DAO_OptionValue', $sql, null, array(array('optionGroup', 'option_group_id', 'option_group_label'))); $sql = "\nSELECT cg.*\nFROM civicrm_custom_group cg\nWHERE cg.is_active = 1\n"; $this->fetch('customGroup', 'CRM_Core_DAO_CustomGroup', $sql, array('id', 'title')); $sql = "\nSELECT f.*\nFROM civicrm_custom_field f,\n civicrm_custom_group cg\nWHERE f.custom_group_id = cg.id\nAND cg.is_active = 1\n"; $this->fetch('customField', 'CRM_Core_DAO_CustomField', $sql, null, array(array('optionGroup', 'option_group_id', 'option_group_label'), array('customGroup', 'custom_group_id', 'custom_group_title'))); $this->fetch('profileGroup', 'CRM_Core_DAO_UFGroup', null, array('id', 'title'), null); $this->fetch('profileField', 'CRM_Core_DAO_UFField', null, null, array(array('profileGroup', 'uf_group_id', 'profile_group_title'))); $buffer = '<?xml version="1.0" encoding="iso-8859-1" ?>'; $buffer .= "\n\n<CustomData>\n"; foreach (array_keys($this->_xml) as $key) { if (!empty($this->_xml[$key]['data'])) { $buffer .= " <{$this->_xml[$key]['scope']}>\n{$this->_xml[$key]['data']} </{$this->_xml[$key]['scope']}>\n"; } else { if ($this->_xml[$key]['required']) { CRM_Core_Error::fatal("No records in DB for {$key}"); } } } $buffer .= "</CustomData>\n"; CRM_Utils_System::download('CustomGroupData.xml', 'text/plain', $buffer); }
function run() { CRM_Utils_System::setTitle(ts('Bank Transaction Exporter')); // get the plugins $plugin_list = CRM_Banking_BAO_PluginInstance::listInstances('export'); $this->assign('plugin_list', $plugin_list); // get the IDs $txbatch2ids = CRM_Banking_PluginModel_Exporter::getIdLists($_REQUEST); $txcount = 0; foreach ($txbatch2ids as $txbatchid => $txbatchcontent) { $txcount += count($txbatchcontent); } $this->assign('txbatch_count', count($txbatch2ids)); $this->assign('tx_count', $txcount); if (!empty($_REQUEST['list'])) { $this->assign('list', $_REQUEST['list']); } if (!empty($_REQUEST['s_list'])) { $this->assign('s_list', $_REQUEST['s_list']); } // check for the page mode if (isset($_REQUEST['exporter-plugin'])) { // EXECUTE // get the plugin instance $plugin_id = $_REQUEST['exporter-plugin']; foreach ($plugin_list as $plugin) { if ($plugin->id == $plugin_id) { break; } } $plugin_instance = $plugin->getInstance(); // TODO: select WHICH mode (this is only file mode) // start exporting $file_data = $plugin_instance->export_file($txbatch2ids, $_REQUEST); // process result (redirect, ...) if (empty($file_data['is_error'])) { $mime_type = mime_content_type($file_data['path']); $buffer = file_get_contents($file_data['path']); CRM_Utils_System::download($file_data['file_name'], $file_data['mime_type'], $buffer, $file_data['file_extension']); } } else { // CONFIGURATION MODE: $plugin_capabilities = array(); foreach ($plugin_list as $plugin) { $capability = ''; $instance = $plugin->getInstance(); if ($instance->does_export_files()) { $capability .= 'F'; } if ($instance->does_export_stream()) { $capability .= 'S'; } $plugin_capabilities[$plugin->id] = $capability; } $this->assign('plugin_capabilities', $plugin_capabilities); } // URLs $this->assign('url_action', CRM_Utils_System::url('civicrm/banking/export')); parent::run(); }
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); } }
/** * This function overrides CRM_CorePage_File::run * If we are trying to access a SecureFile offsite * we run this function. If we determine that we * aren't retrieving this file, fallback on the * core run function: parent::run() * * It is used for Download/View and Delete * */ public function run() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE); $runParent = true; if (is_numeric($id)) { $file = civicrm_api3('File', 'getsingle', array('id' => $id)); $details = json_decode($file['description']); if ($details && property_exists($details, "source") && $details->source == "securefiles") { $action = CRM_Utils_Request::retrieve('action', 'String', $this); //Check Extension level permissions CRM_Securefiles_Permission::checkFilePerms(CRM_Core_Action::ADD, $id, $eid); $backendService = CRM_Securefiles_Backend::getBackendService(); if ($backendService) { if (!($action & CRM_Core_Action::DELETE)) { //Check backend service permissions if ($backendService->checkPermissions(CRM_Core_Action::VIEW, $id, $eid) !== false) { $content = $backendService->downloadFile($file['uri'], $eid); CRM_Utils_System::download($file['uri'], $file['mime_type'], $content); } else { return null; } } //Skip delegating back to the core file handler $runParent = false; } } } if ($runParent) { parent::run(); } }
/** * * @package CRM * @copyright CiviCRM LLC (c) 2004-2013 * $Id$ * */ function run() { session_start(); require_once '../../civicrm.config.php'; require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); // this does not return on failure CRM_Utils_System::authenticateScript(TRUE); require_once 'CRM/Utils/Migrate/Export.php'; $export = new CRM_Utils_Migrate_Export(); $export->build(); CRM_Utils_System::download('CustomGroupData.xml', 'text/plain', $export->toXML()); }
/** * * @package CRM * @copyright CiviCRM LLC (c) 2004-2016 */ function run() { session_start(); require_once '../../civicrm.config.php'; require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); // this does not return on failure CRM_Utils_System::authenticateScript(TRUE); if (!CRM_Core_Permission::check('administer CiviCRM')) { CRM_Utils_System::authenticateAbort("User does not have required permission (administer CiviCRM).\n", TRUE); } require_once 'CRM/Utils/Migrate/Export.php'; $export = new CRM_Utils_Migrate_Export(); $export->build(); CRM_Utils_System::download('CustomGroupData.xml', 'text/plain', $export->toXML()); }
function run() { // fetch the option group / values for // activity type and event_type $optionGroups = "( 'activity_type', 'event_type', 'mapping_type' )"; $sql = "\nSELECT distinct(g.id), g.*\nFROM civicrm_option_group g\nWHERE g.name IN {$optionGroups}\n"; $this->fetch('optionGroup', 'CRM_Core_DAO_OptionGroup', $sql, array('id', 'name')); $sql = "\nSELECT distinct(g.id), g.*\nFROM civicrm_option_group g,\n civicrm_custom_field f,\n civicrm_custom_group cg\nWHERE f.option_group_id = g.id\nAND f.custom_group_id = cg.id\nAND cg.is_active = 1\n"; $this->fetch('optionGroup', 'CRM_Core_DAO_OptionGroup', $sql, array('id', 'name')); $sql = "\nSELECT v.*, g.name as prefix\nFROM civicrm_option_value v,\n civicrm_option_group g\nWHERE v.option_group_id = g.id\nAND g.name IN {$optionGroups}\n"; $this->fetch('optionValue', 'CRM_Core_DAO_OptionValue', $sql, array('value', 'name', 'prefix'), array(array('optionGroup', 'option_group_id', 'option_group_name'))); $sql = "\nSELECT distinct(v.id), v.*, g.name as prefix\nFROM civicrm_option_value v,\n civicrm_option_group g,\n civicrm_custom_field f,\n civicrm_custom_group cg\nWHERE v.option_group_id = g.id\nAND f.option_group_id = g.id\nAND f.custom_group_id = cg.id\nAND cg.is_active = 1\n"; $this->fetch('optionValue', 'CRM_Core_DAO_OptionValue', $sql, array('id', 'name', 'prefix'), array(array('optionGroup', 'option_group_id', 'option_group_name'))); $sql = "\nSELECT rt.*\nFROM civicrm_relationship_type rt\nWHERE rt.is_active = 1\n"; $this->fetch('relationshipType', 'CRM_Contact_DAO_RelationshipType', $sql, array('id', 'name_a_b')); $sql = "\nSELECT lt.*\nFROM civicrm_location_type lt\nWHERE lt.is_active = 1\n"; $this->fetch('locationType', 'CRM_Core_DAO_LocationType', $sql, array('id', 'name')); $sql = "\nSELECT cg.*\nFROM civicrm_custom_group cg\nWHERE cg.is_active = 1\n"; $this->fetch('customGroup', 'CRM_Core_DAO_CustomGroup', $sql, array('id', 'name')); $sql = "\nSELECT f.*\nFROM civicrm_custom_field f,\n civicrm_custom_group cg\nWHERE f.custom_group_id = cg.id\nAND cg.is_active = 1\n"; $this->fetch('customField', 'CRM_Core_DAO_CustomField', $sql, array('id', 'column_name'), array(array('optionGroup', 'option_group_id', 'option_group_name'), array('customGroup', 'custom_group_id', 'custom_group_name'))); $this->fetch('profileGroup', 'CRM_Core_DAO_UFGroup', null, array('id', 'name'), null); $this->fetch('profileField', 'CRM_Core_DAO_UFField', null, null, array(array('profileGroup', 'uf_group_id', 'profile_group_name'))); $sql = "\nSELECT *\nFROM civicrm_uf_join\nWHERE entity_table IS NULL\nAND entity_id IS NULL\n"; $this->fetch('profileJoin', 'CRM_Core_DAO_UFJoin', $sql, null, array(array('profileGroup', 'uf_group_id', 'profile_group_name'))); $this->fetch('mappingGroup', 'CRM_Core_DAO_Mapping', null, array('id', 'name'), array(array('optionValue', 'mapping_type_id', 'mapping_type_name', 'mapping_type'))); $this->fetch('mappingField', 'CRM_Core_DAO_MappingField', null, null, array(array('mappingGroup', 'mapping_id', 'mapping_group_name'), array('locationType', 'location_type_id', 'location_type_name'), array('relationshipType', 'relationship_type_id', 'relationship_type_name'))); $buffer = '<?xml version="1.0" encoding="iso-8859-1" ?>'; $buffer .= "\n\n<CustomData>\n"; foreach (array_keys($this->_xml) as $key) { if (!empty($this->_xml[$key]['data'])) { $buffer .= " <{$this->_xml[$key]['scope']}>\n{$this->_xml[$key]['data']} </{$this->_xml[$key]['scope']}>\n"; } else { if ($this->_xml[$key]['required']) { CRM_Core_Error::fatal("No records in DB for {$key}"); } } } $buffer .= "</CustomData>\n"; CRM_Utils_System::download('CustomGroupData.xml', 'text/plain', $buffer); }
function run() { if (!preg_match('/^[^\\/]+\\.(jpg|jpeg|png|gif)$/i', $_GET['photo'])) { CRM_Core_Error::fatal('Malformed photo name'); } // FIXME Optimize performance of image_url query $sql = "SELECT id FROM civicrm_contact WHERE image_url like %1;"; $params = array(1 => array("%" . $_GET['photo'], 'String')); $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { $cid = $dao->id; } if ($cid) { $config = CRM_Core_Config::singleton(); $buffer = file_get_contents($config->customFileUploadDir . $_GET['photo']); $mimeType = 'image/' . pathinfo($_GET['photo'], PATHINFO_EXTENSION); CRM_Utils_System::download($_GET['photo'], $mimeType, $buffer, NULL, TRUE, 'inline'); CRM_Utils_System::civiExit(); } else { CRM_Core_Error::fatal('Photo does not exist'); } }
function writeCSVFile($fileName, &$header, &$rows, $titleHeader = null) { require_once 'CRM/Utils/System.php'; CRM_Utils_System::download(CRM_Utils_String::munge($fileName), 'text/x-csv', CRM_Core_DAO::$_nullObject, 'csv', false); self::makeCSVTable($header, $rows, $titleHeader, true); }
/** * Write a CSV file to the browser output. * * @param string $fileName * The name of the file that will be downloaded (this is sent to the browser). * @param array $header * An array of the headers. * @param array $rows * An array of arrays of the table contents. * @param string $titleHeader * If set this will be the title in the CSV. * @param bool $outputHeader * Should we output the header row. * @param bool $saveFile * -. * * @return void */ public static function writeCSVFile($fileName, &$header, &$rows, $titleHeader = NULL, $outputHeader = TRUE, $saveFile = NULL) { if ($outputHeader && !$saveFile) { CRM_Utils_System::download(CRM_Utils_String::munge($fileName), 'text/x-csv', CRM_Core_DAO::$_nullObject, 'csv', FALSE); } if (!empty($rows)) { $print = TRUE; if ($saveFile) { $print = FALSE; } return self::makeCSVTable($header, $rows, $titleHeader, $print, $outputHeader); } }