_action & CRM_Core_Action::DELETE) {
$formatName = CRM_Core_BAO_PdfFormat::getFieldValue('CRM_Core_BAO_PdfFormat', $this->_id, 'name');
$this->assign('formatName', $formatName);
return;
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat');
$this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
$this->add('text', 'description', ts('Description'), array('size' => CRM_Utils_Type::HUGE));
$this->add('checkbox', 'is_default', ts('Is this PDF Page Format the default?'));
$this->add('select', 'paper_size', ts('Paper Size'),
array(
0 => ts('- default -'),
) + CRM_Core_BAO_PaperSize::getList(TRUE), FALSE,
array('onChange' => "selectPaper( this.value );")
);
$this->add('static', 'paper_dimensions', NULL, ts('Width x Height'));
$this->add('select', 'orientation', ts('Orientation'), CRM_Core_BAO_PdfFormat::getPageOrientations(), FALSE,
array('onChange' => "updatePaperDimensions();")
);
$this->add('select', 'metric', ts('Unit of Measure'), CRM_Core_BAO_PdfFormat::getUnits(), FALSE,
array('onChange' => "selectMetric( this.value );")
);
$this->add('text', 'margin_left', ts('Left Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'margin_right', ts('Right Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'margin_top', ts('Top Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'margin_bottom', ts('Bottom Margin'), array('size' => 8, 'maxlength' => 8), TRUE);
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Core_BAO_PdfFormat',
$this->_id,
));
$this->addRule('margin_left', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_right', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_top', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_bottom', ts('Margin must be numeric'), 'numeric');
$this->addRule('weight', ts('Weight must be integer'), 'integer');
}
/**
* @return int
*/
public function setDefaultValues() {
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['weight'] = CRM_Utils_Array::value('weight', CRM_Core_BAO_PdfFormat::getDefaultValues(), 0);
}
else {
$defaults = $this->_values;
}
return $defaults;
}
/**
* Process the form submission.
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
// delete PDF Page Format
CRM_Core_BAO_PdfFormat::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected PDF Page Format has been deleted.'), ts('Record Deleted'), 'success');
return;
}
$values = $this->controller->exportValues($this->getName());
$values['is_default'] = isset($values['is_default']);
$bao = new CRM_Core_BAO_PdfFormat();
$bao->savePdfFormat($values, $this->_id);
$status = ts('Your new PDF Page Format titled %1 has been saved.', array(1 => $values['name']), ts('Saved'), 'success');
if ($this->_action & CRM_Core_Action::UPDATE) {
$status = ts('Your PDF Page Format titled %1 has been updated.', array(1 => $values['name']), ts('Saved'), 'success');
}
CRM_Core_Session::setStatus($status);
}
}