From b3e303a208735847034fe1694f9bdad6722ab5c9 Mon Sep 17 00:00:00 2001 From: Jagadedes Date: Wed, 12 Nov 2014 17:27:00 +0530 Subject: [PATCH] fixed beta 1 bugs: 31069 divider between contrib pages. removed direct use of request var --- CRM/Wci/Form/CreateWidget.php | 7 +-- CRM/Wci/Form/NewEmbedCode.php | 4 +- CRM/Wci/Form/ProgressBar.php | 65 +++++++++++++++++--------- CRM/Wci/Page/ManageEmbedCode.php | 5 +- CRM/Wci/Page/ProgressBarList.php | 10 ++-- CRM/Wci/Page/WidgetList.php | 5 +- addmore.js | 5 +- templates/CRM/Wci/Form/ProgressBar.tpl | 10 ++++ 8 files changed, 73 insertions(+), 38 deletions(-) diff --git a/CRM/Wci/Form/CreateWidget.php b/CRM/Wci/Form/CreateWidget.php index f6f64b7..b75f47c 100644 --- a/CRM/Wci/Form/CreateWidget.php +++ b/CRM/Wci/Form/CreateWidget.php @@ -146,8 +146,8 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { /*$query = "SELECT pb.id as pbid, w.* FROM civicrm_wci_widget w INNER JOIN civicrm_wci_progress_bar pb on pb.id = w.progress_bar_id where w.id=" . $this->_id;*/ - $query = "SELECT * FROM civicrm_wci_widget WHERE id=" . $this->_id; - $params = array(); + $query = "SELECT * FROM civicrm_wci_widget WHERE id=%1"; + $params = array(1 => array($this->_id, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget'); @@ -334,7 +334,8 @@ where w.id=" . $this->_id;*/ } } catch (Exception $e) { - CRM_Core_Session::setStatus(ts('Failed to create widget'), '', 'error'); + CRM_Core_Session::setStatus(ts('Failed to create widget. '). + $e->getMessage(), '', 'error'); $transaction->rollback(); } diff --git a/CRM/Wci/Form/NewEmbedCode.php b/CRM/Wci/Form/NewEmbedCode.php index 7d8372d..793123f 100644 --- a/CRM/Wci/Form/NewEmbedCode.php +++ b/CRM/Wci/Form/NewEmbedCode.php @@ -40,8 +40,8 @@ class CRM_Wci_Form_NewEmbedCode extends CRM_Core_Form { )); if (isset($this->_id)) { - $query = "SELECT * FROM civicrm_wci_embed_code WHERE id=" . $this->_id; - $params = array(); + $query = "SELECT * FROM civicrm_wci_embed_code WHERE id= %1"; + $params = array(1 => array($this->_id, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_EmbedCode'); diff --git a/CRM/Wci/Form/ProgressBar.php b/CRM/Wci/Form/ProgressBar.php index 0be406e..1b5e5e0 100644 --- a/CRM/Wci/Form/ProgressBar.php +++ b/CRM/Wci/Form/ProgressBar.php @@ -21,8 +21,8 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { $count = 1; if (isset($this->_id)) { /** Updating existing progress bar*/ - $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $this->_id; - $params = array(); + $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'); @@ -37,8 +37,8 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { 'goal_amount' => $con_page[$dao->id]['goal_amount'])); } - $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $this->_id; - $params = array(); + $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =%1"; + $params = array(1 => array($this->_id, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBarFormula'); @@ -138,22 +138,32 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { try { $transaction = new CRM_Core_Transaction(); - $sql = "UPDATE civicrm_wci_progress_bar SET name = '". $_REQUEST['progressbar_name'] . - "', starting_amount = '" . $_REQUEST['starting_amount'] . - "', goal_amount = '" . $_REQUEST['goal_amount'] . - "' where id =".$this->_id; - - CRM_Core_DAO::executeQuery($sql); - /** Delete existiing formula fields and add fields fresh*/ - CRM_Core_DAO::executeQuery('DELETE FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id=' . $this->_id); + $sql = "UPDATE civicrm_wci_progress_bar SET name = %1, + starting_amount = %2, goal_amount = %3 where id = %4"; + CRM_Core_DAO::executeQuery($sql, + array(1=>array($_REQUEST['progressbar_name'], 'String'), + 2=>array($_REQUEST['starting_amount'], 'Float'), + 3=>array($_REQUEST['goal_amount'], 'Float'), + 4=>array($this->_id, 'Integer'), + )); + /** Delete existiing formula fields and add fields fresh*/ + CRM_Core_DAO::executeQuery('DELETE FROM civicrm_wci_progress_bar_formula + WHERE progress_bar_id=%1', array(1 => array($this->_id, 'Integer'))); + 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) - VALUES ('" . $_REQUEST[$page] . "','" . $this->_id . "','" . $_REQUEST[$perc] . "')"; - CRM_Core_DAO::executeQuery($sql); + $sql = "INSERT INTO civicrm_wci_progress_bar_formula + (contribution_page_id, progress_bar_id, percentage) + VALUES (%1, %2, %3)"; + + CRM_Core_DAO::executeQuery($sql, + array(1 => array($_REQUEST[$page], 'Integer'), + 2 => array($this->_id, 'Integer'), + 3 => array($_REQUEST[$perc], 'Float'), + )); } $transaction->commit(); @@ -167,27 +177,36 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { } else { - $sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount) - VALUES ('" . $_REQUEST['progressbar_name'] . "','" . $_REQUEST['starting_amount'] . "','" . $_REQUEST['goal_amount'] . "')"; + $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'), + )); $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) - VALUES ('" . $_REQUEST[$page] . "','" . $progressbar_id . "','" . $_REQUEST[$perc] . "')"; + $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'), + )); endfor; $transaction->commit(); CRM_Utils_System::redirect('civicrm/wci/progress-bar?reset=1'); } catch (Exception $e) { - //TODO - print_r($e->getMessage()); + CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . + $e->getMessage(), '', 'error'); $transaction->rollback(); } $elem = $this->getElement('contrib_count'); diff --git a/CRM/Wci/Page/ManageEmbedCode.php b/CRM/Wci/Page/ManageEmbedCode.php index d5b15a8..67d7a38 100644 --- a/CRM/Wci/Page/ManageEmbedCode.php +++ b/CRM/Wci/Page/ManageEmbedCode.php @@ -30,8 +30,9 @@ class CRM_Wci_Page_ManageEmbedCode extends CRM_Core_Page { try { $transaction = new CRM_Core_Transaction(); - $sql = "DELETE FROM civicrm_wci_embed_code where id = " . $id; - CRM_Core_DAO::executeQuery($sql); + $sql = "DELETE FROM civicrm_wci_embed_code where id = %1"; + $params = array(1 => array($id, 'Integer')); + CRM_Core_DAO::executeQuery($sql, $params); $transaction->commit(); } catch (Exception $e) { diff --git a/CRM/Wci/Page/ProgressBarList.php b/CRM/Wci/Page/ProgressBarList.php index a0a33cd..b20e6d5 100644 --- a/CRM/Wci/Page/ProgressBarList.php +++ b/CRM/Wci/Page/ProgressBarList.php @@ -30,11 +30,13 @@ class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page { $errorScope = CRM_Core_TemporaryErrorScope::useException(); try { $transaction = new CRM_Core_Transaction(); - $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = " . $id; - CRM_Core_DAO::executeQuery($sql); + $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = %1"; + $params = array(1 => array($id, 'Integer')); + CRM_Core_DAO::executeQuery($sql, $params); - $sql = "DELETE FROM civicrm_wci_progress_bar where id = " . $id; - CRM_Core_DAO::executeQuery($sql); + $sql = "DELETE FROM civicrm_wci_progress_bar where id = %1"; + $params = array(1 => array($id, 'Integer')); + CRM_Core_DAO::executeQuery($sql, $params); $transaction->commit(); } catch (Exception $e) { diff --git a/CRM/Wci/Page/WidgetList.php b/CRM/Wci/Page/WidgetList.php index 3335b83..b45209f 100644 --- a/CRM/Wci/Page/WidgetList.php +++ b/CRM/Wci/Page/WidgetList.php @@ -30,8 +30,9 @@ class CRM_Wci_Page_WidgetList extends CRM_Core_Page { try { $transaction = new CRM_Core_Transaction(); - $sql = "DELETE FROM civicrm_wci_widget where id = " . $id; - CRM_Core_DAO::executeQuery($sql); + $sql = "DELETE FROM civicrm_wci_widget where id = %1"; + $params = array(1 => array($id, 'Integer')); + CRM_Core_DAO::executeQuery($sql, $params); $transaction->commit(); } catch (Exception $e) { diff --git a/addmore.js b/addmore.js index 9754d14..1120d21 100644 --- a/addmore.js +++ b/addmore.js @@ -4,12 +4,13 @@ cj(function ( $ ) { $(document).ready(function(){ var count = parseInt($('input[name=contrib_count]').val()); for ( var i = 2; i <= count; i++ ) { + $('#' + "contribution_page_" + i).parent().parent().before('

'); $('#' + "contribution_page_" + i).after( ' Remove'); $('#' + "contribution_page_" + i).parent().parent().attr("id", "crm-section-con-" + i); $('#' + "percentage_" + i).parent().parent().attr("id", 'crm-section-per-' + i); } - $('#percentage_1').after(''); + $('#goal_amount').parent().after('

'); }); $("#ProgressBar").validate({ rules: { @@ -44,7 +45,7 @@ cj(function ( $ ) { c_page_sel.attr("name", "contribution_page_" + count); var id_section = "crm-section-con-" + count; - var sect_tag = "

"; + var sect_tag = "

"; $('#addmore_link').parent().parent().before(sect_tag); var id_content = "content_con-" + count; diff --git a/templates/CRM/Wci/Form/ProgressBar.tpl b/templates/CRM/Wci/Form/ProgressBar.tpl index eda9b1c..ae6889d 100644 --- a/templates/CRM/Wci/Form/ProgressBar.tpl +++ b/templates/CRM/Wci/Form/ProgressBar.tpl @@ -1,3 +1,13 @@ +{literal} + +{/literal} {* HEADER *}
-- 2.25.1