コード例 #1
0
 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         // delete Label Format
         CRM_Core_BAO_LabelFormat::del($this->_id, $this->_group);
         CRM_Core_Session::setStatus(ts('Selected Label Format has been deleted.'), ts('Record Deleted'), 'success');
         return;
     }
     if ($this->_action & CRM_Core_Action::COPY) {
         // make a copy of the Label Format
         $labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id, $this->_group);
         $newlabel = ts('Copy of %1', array(1 => $labelFormat['label']));
         $list = CRM_Core_BAO_LabelFormat::getList(TRUE, $this->_group);
         $count = 1;
         while (in_array($newlabel, $list)) {
             $count++;
             $newlabel = ts('Copy %1 of %2', array(1 => $count, 2 => $labelFormat['label']));
         }
         $labelFormat['label'] = $newlabel;
         $labelFormat['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName();
         $labelFormat['is_default'] = 0;
         $labelFormat['is_reserved'] = 0;
         $bao = new CRM_Core_BAO_LabelFormat();
         $bao->saveLabelFormat($labelFormat, NULL, $this->_group);
         CRM_Core_Session::setStatus(ts('%1 has been created.', array(1 => $labelFormat['label'])), ts('Saved'), 'success');
         return;
     }
     $values = $this->controller->exportValues($this->getName());
     // since we currently support only mailing label format
     $values['label_type'] = 'label_format';
     $values['is_default'] = isset($values['is_default']);
     // Restore field names that were converted because they are illegal PHP/SMARTY variable names
     if (isset($values['paper_size'])) {
         $values['paper-size'] = $values['paper_size'];
         unset($values['paper_size']);
     }
     if (isset($values['font_name'])) {
         $values['font-name'] = $values['font_name'];
         unset($values['font_name']);
     }
     if (isset($values['font_size'])) {
         $values['font-size'] = $values['font_size'];
         unset($values['font_size']);
     }
     $style = '';
     if (isset($values['bold'])) {
         $style .= 'B';
     }
     if (isset($values['italic'])) {
         $style .= 'I';
     }
     $values['font-style'] = $style;
     $bao = new CRM_Core_BAO_LabelFormat();
     $bao->saveLabelFormat($values, $this->_id, $values['label_type']);
     $status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label']));
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $status = ts('Your Label Format titled <strong>%1</strong> has been updated.', array(1 => $values['label']));
     }
     CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
 }
コード例 #2
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         // delete Label Format
         CRM_Core_BAO_LabelFormat::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Label Format has been deleted.'));
         return;
     }
     if ($this->_action & CRM_Core_Action::COPY) {
         // make a copy of the Label Format
         $labelFormat = CRM_Core_BAO_LabelFormat::getById($this->_id);
         $list = CRM_Core_BAO_LabelFormat::getList(TRUE);
         $count = 1;
         $prefix = ts('Copy of ');
         while (in_array($prefix . $labelFormat['label'], $list)) {
             $prefix = ts('Copy') . ' (' . ++$count . ') ' . ts('of ');
         }
         $labelFormat['label'] = $prefix . $labelFormat['label'];
         $labelFormat['grouping'] = CRM_Core_BAO_LabelFormat::customGroupName();
         $labelFormat['is_default'] = 0;
         $labelFormat['is_reserved'] = 0;
         $bao = new CRM_Core_BAO_LabelFormat();
         $bao->saveLabelFormat($labelFormat);
         CRM_Core_Session::setStatus($labelFormat['label'] . ts(' has been created.'));
         return;
     }
     $values = $this->controller->exportValues($this->getName());
     $values['is_default'] = isset($values['is_default']);
     // Restore field names that were converted because they are illegal PHP/SMARTY variable names
     if (isset($values['paper_size'])) {
         $values['paper-size'] = $values['paper_size'];
         unset($values['paper_size']);
     }
     if (isset($values['font_name'])) {
         $values['font-name'] = $values['font_name'];
         unset($values['font_name']);
     }
     if (isset($values['font_size'])) {
         $values['font-size'] = $values['font_size'];
         unset($values['font_size']);
     }
     $style = '';
     if (isset($values['bold'])) {
         $style .= 'B';
     }
     if (isset($values['italic'])) {
         $style .= 'I';
     }
     $values['font-style'] = $style;
     $bao = new CRM_Core_BAO_LabelFormat();
     $bao->saveLabelFormat($values, $this->_id);
     $status = ts('Your new Label Format titled <strong>%1</strong> has been saved.', array(1 => $values['label']));
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $status = ts('Your Label Format titled <strong>%1</strong> has been updated.', array(1 => $values['label']));
     }
     CRM_Core_Session::setStatus($status);
 }