Commit a1cb883f authored by DaveD's avatar DaveD
Browse files

Allow deleting of receipt image files

parent efcfae2a
<?php
use CRM_Cdntaxreceipts_ExtensionUtil as E;
/**
* Callback for deleting template images
*/
class CRM_Cdntaxreceipts_Form_ImageDelete extends CRM_Core_Form {
public function buildQuickForm() {
parent::buildQuickForm();
$type = CRM_Utils_Request::retrieve('type', 'String', $this);
if (empty($type)) {
CRM_Core_Error::statusBounce(E::ts('Missing type'));
return;
}
$typeLabels = $this->getTypeLabels();
if (!isset($typeLabels[$type])) {
CRM_Core_Error::statusBounce(E::ts('Unknown type'));
return;
}
CRM_Utils_System::setTitle(E::ts('Delete Image'));
$this->add('hidden', 'imagetype', $type);
$this->assign('imagetype', $typeLabels[$type]);
$this->addButtons(array(
array(
'type' => 'submit',
'name' => E::ts('Delete'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => E::ts('Cancel'),
),
));
}
public function postProcess() {
parent::postProcess();
$type = $this->exportValues()['imagetype'];
if (empty($type)) {
CRM_Core_Error::statusBounce(E::ts('Missing type'));
return;
}
$filename = Civi::settings()->get($type);
if (empty($filename)) {
CRM_Core_Error::statusBounce(E::ts('Setting does not exist'));
return;
}
$filename = CRM_Core_Config::singleton()->customFileUploadDir . $filename;
if (file_exists($filename)) {
Civi::settings()->set($type, NULL);
unlink($filename);
}
CRM_Core_Session::setStatus(E::ts('The %1 file has been deleted.', array(1 => basename($filename))), '', 'success');
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/cdntaxreceipts/settings', 'reset=1'));
}
/**
* Needs to be a function since we need to use ts().
* @return array
*/
private function getTypeLabels(): array {
return array(
'receipt_logo' => E::ts('Logo'),
'receipt_signature' => E::ts('Signature'),
'receipt_watermark' => E::ts('Watermark'),
'receipt_pdftemplate' => E::ts('PDF Template'),
);
}
}
......@@ -12,9 +12,12 @@ class CRM_Cdntaxreceipts_Form_Settings extends CRM_Core_Form {
CONST SETTINGS = 'CDNTaxReceipts';
protected $unsavedChangesWarn = TRUE;
function buildQuickForm() {
CRM_Utils_System::setTitle(ts('Configure CDN Tax Receipts', array('domain' => 'org.civicrm.cdntaxreceipts')));
CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.cdntaxreceipts', 'css/civicrm_cdntaxreceipts.css');
$this->processOrgOptions('build');
$this->processReceiptOptions('build');
......
......@@ -22,3 +22,7 @@
#crm-container .cdntax_summary label {
margin-left: 5px;
}
.cdntaxreceipts-imagedelete {
margin-left: 1em;
}
<div class="crm-block crm-form-block crm-miscellaneous-form-block">
{ts 1=$imagetype domain='org.civicrm.cdntaxreceipts'}Delete the <em>%1</em> file?{/ts}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>
......@@ -67,7 +67,7 @@
<p class="description">{ts domain='org.civicrm.cdntaxreceipts'}Logo size: 280x120 pixels; File types allowed: .jpg .png.{/ts}</p>
{if $receipt_logo}
{if $receipt_logo_class}<span class="crm-error">The file {$receipt_logo} was not found</span>
{else}<p class="label">Current {$form.receipt_logo.label}: {$receipt_logo}</p>{/if}
{else}<p class="label">Current {$form.receipt_logo.label}: {$receipt_logo}<span class="cdntaxreceipts-imagedelete"><a href="{crmURL p='civicrm/cdntaxreceipts/imagedelete' q='type=receipt_logo'}">{ts}Delete{/ts}</a></span></p>{/if}
{/if}</td>
</tr>
<tr>
......@@ -76,7 +76,7 @@
<p class="description">{ts domain='org.civicrm.cdntaxreceipts'}Signature size: 141x58 pixels; File types allowed: .jpg .png.{/ts}</p>
{if $receipt_signature}
{if $receipt_signature_class}<span class="crm-error">The file {$receipt_signature} was not found</span>
{else}<p class="label">Current {$form.receipt_signature.label}: {$receipt_signature}</p>{/if}
{else}<p class="label">Current {$form.receipt_signature.label}: {$receipt_signature}<span class="cdntaxreceipts-imagedelete"><a href="{crmURL p='civicrm/cdntaxreceipts/imagedelete' q='type=receipt_signature'}">{ts}Delete{/ts}</a></span></p>{/if}
{/if}</td>
</tr>
<tr>
......@@ -85,7 +85,7 @@
<p class="description">{ts domain='org.civicrm.cdntaxreceipts'}Watermark Image size: 250x250 pixels; File types allowed: .jpg .png.{/ts}</p>
{if $receipt_watermark}
{if $receipt_watermark_class}<span class="crm-error">The file {$receipt_watermark} was not found</span>
{else}<p class="label">Current {$form.receipt_watermark.label}: {$receipt_watermark}</p>{/if}
{else}<p class="label">Current {$form.receipt_watermark.label}: {$receipt_watermark}<span class="cdntaxreceipts-imagedelete"><a href="{crmURL p='civicrm/cdntaxreceipts/imagedelete' q='type=receipt_watermark'}">{ts}Delete{/ts}</a></span></p>{/if}
{/if}</td>
</tr>
<tr>
......@@ -94,7 +94,7 @@
<p class="description">{ts domain='org.civicrm.cdntaxreceipts'}Upload your own PDF template: .pdf{/ts}</p>
{if $receipt_pdftemplate}
{if $receipt_pdftemplate_class}<span class="crm-error">The file {$receipt_pdftemplate} was not found</span>
{else}<p class="label">Current {$form.receipt_pdftemplate.label}: {$receipt_pdftemplate}</p>{/if}
{else}<p class="label">Current {$form.receipt_pdftemplate.label}: {$receipt_pdftemplate}<span class="cdntaxreceipts-imagedelete"><a href="{crmURL p='civicrm/cdntaxreceipts/imagedelete' q='type=receipt_pdftemplate'}">{ts}Delete{/ts}</a></span></p>{/if}
{/if}</td>
</tr>
</tbody>
......
......@@ -12,6 +12,12 @@
<title>Settings</title>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/cdntaxreceipts/imagedelete</path>
<page_callback>CRM_Cdntaxreceipts_Form_ImageDelete</page_callback>
<title>Image Delete</title>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/cdntaxreceipts/open</path>
<page_callback>CRM_Cdntaxreceipts_Page_OpenEvent</page_callback>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment