e3a72753e4815b52a0a6d1a27939aea68e949e86
3 require_once 'CRM/Core/Form.php';
4 require_once 'wci-helper-functions.php';
5 require_once 'CRM/Wci/BAO/ProgressBar.php';
8 * Form controller class
10 * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
12 class CRM_Wci_Form_ProgressBar
extends CRM_Core_Form
{
14 function preProcess() {
16 CRM_Core_Resources
::singleton()->addScriptFile('org.civicrm.wci', 'addmore.js');
19 function buildQuickForm() {
22 'progressbar_name', // field name
23 'Name', // field label
28 'starting_amount', // field name
29 'Starting amount', // field label
34 'goal_amount', // field name
35 'Goal amount', // field label
39 'select', // field type
40 'contribution_page_1', // field name
41 'Contribution page', // field label
42 getContributionPageOptions(), // list of options
47 'percentage_1', // field name
48 'Percentage', // field label
52 $this->addElement('link', 'addmore_link',' ', 'addmore', 'Add more');
54 $this->addElement('hidden', 'contrib_count', '1');
56 $this->addButtons(array(
64 // export form elements
65 $this->assign('elementNames', $this->getRenderableElementNames());
67 parent
::buildQuickForm();
70 function postProcess() {
72 $sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount)
73 VALUES ('" . $_REQUEST['progressbar_name'] . "','" . $_REQUEST['starting_amount'] . "','" . $_REQUEST['goal_amount'] . "')";
75 CRM_Core_DAO
::executeQuery($sql);
77 $progressbar_id = CRM_Core_DAO
::singleValueQuery('SELECT LAST_INSERT_ID()');
78 for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++
):
79 $page = 'contribution_page_' . (string)$i;
80 $perc = 'percentage_' . (string)$i;
82 $sql = "INSERT INTO civicrm_wci_progress_bar_formula (contribution_page_id, progress_bar_id, percentage)
83 VALUES ('" . $_REQUEST[$page] . "','" . $progressbar_id . "','" . $_REQUEST[$perc] . "')";
85 CRM_Core_DAO
::executeQuery($sql);
88 catch (Exception
$e) {
92 parent
::postProcess();
93 $elem = $this->getElement('contrib_count');
98 * Get the fields/elements defined in this form.
100 * @return array (string)
102 function getRenderableElementNames() {
103 // The _elements list includes some items which should not be
104 // auto-rendered in the loop -- such as "qfKey" and "buttons". These
105 // items don't have labels. We'll identify renderable by filtering on
107 $elementNames = array();
108 foreach ($this->_elements
as $element) {
109 $label = $element->getLabel();
110 if (!empty($label)) {
111 $elementNames[] = $element->getName();
114 return $elementNames;