31453 31498 code cleanup
[com.zyxware.civiwci.git] / CRM / Wci / Form / ProgressBar.php
index 04428ae2caedba303f71e580af7712d2a79f5cdc..948080159f64cec231886092e159a7740b9dac14 100644 (file)
@@ -1,5 +1,26 @@
 <?php
-
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM Widget Creation Interface (WCI) Version 1.0                |
+ +--------------------------------------------------------------------+
+ | Copyright Zyxware Technologies (c) 2014                            |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM WCI.                                |
+ |                                                                    |
+ | CiviCRM WCI is free software; you can copy, modify, and distribute |
+ | it under the terms of the GNU Affero General Public License        |
+ | Version 3, 19 November 2007.                                       |
+ |                                                                    |
+ | CiviCRM WCI is distributed in the hope that it will be useful,     |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of     |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License along with this program; if not, contact Zyxware           |
+ | Technologies at info[AT]zyxware[DOT]com.                           |
+ +--------------------------------------------------------------------+
+*/
 require_once 'CRM/Core/Form.php';
 require_once 'wci-helper-functions.php';
 require_once 'CRM/Wci/BAO/ProgressBar.php';
@@ -11,19 +32,21 @@ require_once 'CRM/Wci/DAO/ProgressBarFormula.php';
  * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
  */
 class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
-  private $_id;  
+  private $_id;
+
   function preProcess() {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'REQUEST');
     CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.wci', 'js/addmore.js');
     parent::preProcess();
   }
+
   function fillData() {
     $count = 1;
     if (isset($this->_id)) {
       /** Updating existing progress bar*/
       $query = "SELECT * FROM civicrm_wci_progress_bar where id=%1";
       $params = array(1 => array($this->_id, 'Integer'));
-      
+
       $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
 
       while ($dao->fetch()) {
@@ -36,7 +59,7 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
         $this->setDefaults(array(
               'goal_amount' => $con_page[$dao->id]['goal_amount']));
       }
-       
+
       $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =%1";
       $params = array(1 => array($this->_id, 'Integer'));
 
@@ -59,7 +82,7 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
           'Percentage of contribution taken', // field label
           false // is required
         );
-        //save formula id 
+        //save formula id
         $this->addElement('hidden', 'contrib_elem_'.$count , $for_page[$dao->id]['id']);
 
         $this->setDefaults(array(
@@ -71,7 +94,7 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
       }
       CRM_Utils_System::setTitle(ts('Edit Progress Bar'));
       $count--; // because last iteration increments it to the next
-    }  
+    }
     else {
       /** New progress bar*/
       $this->add(
@@ -89,12 +112,12 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
       );
       CRM_Utils_System::setTitle(ts('Create Progress Bar'));
     }
-    
+
     $this->addElement('hidden', 'contrib_count', $count);
   }
-  
+
   function buildQuickForm() {
-  
+
     $this->add(
       'text', // field type
       'progressbar_name', // field name
@@ -113,9 +136,9 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
       'Goal amount', // field label
       true // is required
     )->setSize(35);
-    
+
     $this->fillData();
-    
+
     $this->addElement('link', 'addmore_link',' ', 'addmore', 'Add another contribution page');
 
     $this->addButtons(array(
@@ -128,7 +151,7 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
 
     // export form elements
     $this->assign('elementNames', $this->getRenderableElementNames());
-    
+
     parent::buildQuickForm();
   }
 
@@ -137,11 +160,11 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
     if (isset($this->_id)) {
       try {
         $transaction = new CRM_Core_Transaction();
-        
-        $sql = "UPDATE civicrm_wci_progress_bar SET name = %1, 
+
+        $sql = "UPDATE civicrm_wci_progress_bar SET name = %1,
           starting_amount = %2, goal_amount = %3 where id = %4";
-        
-        CRM_Core_DAO::executeQuery($sql, 
+
+        CRM_Core_DAO::executeQuery($sql,
               array(1=>array($_REQUEST['progressbar_name'], 'String'),
               2=>array($_REQUEST['starting_amount'], 'Float'),
               3=>array($_REQUEST['goal_amount'], 'Float'),
@@ -156,16 +179,16 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
           $perc = 'percentage_' . (string)$i;
 
           $sql = "INSERT INTO civicrm_wci_progress_bar_formula
-            (contribution_page_id, progress_bar_id, percentage) 
+            (contribution_page_id, progress_bar_id, percentage)
             VALUES (%1, %2, %3)";
 
-          CRM_Core_DAO::executeQuery($sql, 
+          CRM_Core_DAO::executeQuery($sql,
             array(1 => array($_REQUEST[$page], 'Integer'),
             2 => array($this->_id, 'Integer'),
             3 => array($_REQUEST[$perc], 'Float'),
           ));
         }
-        
+
         $transaction->commit();
         CRM_Core_Session::setStatus(ts('Progress bar created successfuly'), '', 'success');
         CRM_Utils_System::redirect('progress-bar?reset=1');
@@ -174,28 +197,28 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
         CRM_Core_Session::setStatus(ts('Failed to create progress bar'), '', 'error');
         $transaction->rollback();
       }
-    
-    } 
+
+    }
     else {
-      $sql = "INSERT INTO civicrm_wci_progress_bar 
+      $sql = "INSERT INTO civicrm_wci_progress_bar
               (name, starting_amount, goal_amount) VALUES (%1, %2, %3)";
       try {
         $transaction = new CRM_Core_Transaction();
-        CRM_Core_DAO::executeQuery($sql, 
+        CRM_Core_DAO::executeQuery($sql,
           array(1=>array($_REQUEST['progressbar_name'], 'String'),
           2=>array($_REQUEST['starting_amount'], 'Float'),
-          3=>array($_REQUEST['goal_amount'], 'Float'),  
+          3=>array($_REQUEST['goal_amount'], 'Float'),
         ));
         $progressbar_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()');
         for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++):
           $page = 'contribution_page_' . (string)$i;
           $perc = 'percentage_' . (string)$i;
 
-          $sql = "INSERT INTO civicrm_wci_progress_bar_formula 
-          (contribution_page_id, progress_bar_id, percentage) 
+          $sql = "INSERT INTO civicrm_wci_progress_bar_formula
+          (contribution_page_id, progress_bar_id, percentage)
           VALUES (%1, %2, %3)";
-          
-          CRM_Core_DAO::executeQuery($sql, 
+
+          CRM_Core_DAO::executeQuery($sql,
           array(1 => array($_REQUEST[$page], 'Integer'),
           2 => array($progressbar_id, 'Integer'),
           3 => array($_REQUEST[$perc], 'Float'),
@@ -203,14 +226,14 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
         endfor;
         $transaction->commit();
         CRM_Utils_System::redirect('civicrm/wci/progress-bar?reset=1');
-      }    
+      }
       catch (Exception $e) {
-        CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . 
+        CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') .
         $e->getMessage(), '', 'error');
         $transaction->rollback();
       }
       $elem = $this->getElement('contrib_count');
-      $elem->setValue('1');    
+      $elem->setValue('1');
     }
     parent::postProcess();
   }
@@ -235,4 +258,3 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form {
     return $elementNames;
   }
 }
-