From cde5123304ec74d612b030cdaa1263588be57fa8 Mon Sep 17 00:00:00 2001 From: Jagadedes Date: Tue, 30 Sep 2014 17:47:03 +0530 Subject: [PATCH] progressbar listing page --- CRM/Wci/Form/ProgressBar.php | 101 ++++++++++++----- CRM/Wci/Page/ProgressBarList.php | 100 +++++++++++++++++ addmore.js | 50 +++++---- templates/CRM/Wci/Page/ProgressBarList.tpl | 108 +++++++++++++++++++ wci.php | 119 ++++++++++----------- xml/Menu/wci.xml | 6 ++ 6 files changed, 372 insertions(+), 112 deletions(-) create mode 100644 CRM/Wci/Page/ProgressBarList.php create mode 100644 templates/CRM/Wci/Page/ProgressBarList.tpl diff --git a/CRM/Wci/Form/ProgressBar.php b/CRM/Wci/Form/ProgressBar.php index 0992e9e..9d84cce 100644 --- a/CRM/Wci/Form/ProgressBar.php +++ b/CRM/Wci/Form/ProgressBar.php @@ -3,6 +3,7 @@ require_once 'CRM/Core/Form.php'; require_once 'wci-helper-functions.php'; require_once 'CRM/Wci/BAO/ProgressBar.php'; +require_once 'CRM/Wci/DAO/ProgressBarFormula.php'; /** * Form controller class @@ -10,13 +11,56 @@ require_once 'CRM/Wci/BAO/ProgressBar.php'; * @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference */ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { - + private $_id; function preProcess() { - CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.wci', 'addmore.js'); parent::preProcess(); + + } + function FillData() { + $_id = CRM_Utils_Request::retrieve('id', 'Positive', + $this, FALSE, NULL, 'REQUEST' + ); + if (isset($_id)) { + $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $_id; + $params = array(); + + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBar'); + + while ($dao->fetch()) { + $con_page[$dao->id] = array(); + CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]); + $this->setDefaults(array( + 'progressbar_name' => $con_page[$dao->id]['name'])); + $this->setDefaults(array( + 'starting_amount' => $con_page[$dao->id]['starting_amount'])); + $this->setDefaults(array( + 'goal_amount' => $con_page[$dao->id]['goal_amount'])); + } + + $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $_id; + $params = array(); + echo $query . '
'; + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBarFormula'); + + $count = 1; + echo count($dao); + while ($dao->fetch()) { + $for_page[$dao->id] = array(); + CRM_Core_DAO::storeValues($dao, $for_page[$dao->id]); + + $this->setDefaults(array( + 'contribution_page_'.$count => $for_page[$dao->id]['contribution_page_id'])); + $this->setDefaults(array( + 'percentage_'.$count => $for_page[$dao->id]['percentage'])); + $count++; + } + } + } + function buildQuickForm() { + $this->add( 'text', // field type 'progressbar_name', // field name @@ -49,6 +93,8 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { true // is required ); + $this->FillData(); + $this->addElement('link', 'addmore_link',' ', 'addmore', 'Add more'); $this->addElement('hidden', 'contrib_count', '1'); @@ -68,32 +114,35 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { } function postProcess() { - - $sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount) - VALUES ('" . $_REQUEST['progressbar_name'] . "','" . $_REQUEST['starting_amount'] . "','" . $_REQUEST['goal_amount'] . "')"; - $errorScope = CRM_Core_TemporaryErrorScope::useException(); - try { - $transaction = new CRM_Core_Transaction(); - CRM_Core_DAO::executeQuery($sql); - $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] . "')"; - + if (isset($_id)){ + + } else { + $sql = "INSERT INTO civicrm_wci_progress_bar (name, starting_amount, goal_amount) + VALUES ('" . $_REQUEST['progressbar_name'] . "','" . $_REQUEST['starting_amount'] . "','" . $_REQUEST['goal_amount'] . "')"; + $errorScope = CRM_Core_TemporaryErrorScope::useException(); + try { + $transaction = new CRM_Core_Transaction(); CRM_Core_DAO::executeQuery($sql); - endfor; - } - catch (Exception $e) { - //TODO - print_r($e->getMessage()); - $transaction->rollback(); - } + $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] . "')"; + + CRM_Core_DAO::executeQuery($sql); + endfor; + } + catch (Exception $e) { + //TODO + print_r($e->getMessage()); + $transaction->rollback(); + } + $elem = $this->getElement('contrib_count'); + $elem->setValue('1'); + } parent::postProcess(); - $elem = $this->getElement('contrib_count'); - $elem->setValue('1'); } /** diff --git a/CRM/Wci/Page/ProgressBarList.php b/CRM/Wci/Page/ProgressBarList.php new file mode 100644 index 0000000..e9f9716 --- /dev/null +++ b/CRM/Wci/Page/ProgressBarList.php @@ -0,0 +1,100 @@ +assign('action', $action); + $id = CRM_Utils_Request::retrieve('id', 'Positive', + $this, FALSE, 0 + ); + + + if ($action & CRM_Core_Action::UPDATE) { + echo "UPDATE clicked"; + $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar', + 'Edit Progressbar', + CRM_Core_Action::UPDATE + ); + $controller->set('id', $id); + $controller->process(); + return $controller->run(); +// return; + } elseif ($action & CRM_Core_Action::DELETE) { + echo "delete clicked"; +// return; + } + + // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml + CRM_Utils_System::setTitle(ts('ProgressBarList')); + + // Example: Assign a variable for use in a template + $this->assign('currentTime', date('Y-m-d H:i:s')); + + $query = "SELECT * FROM civicrm_wci_progress_bar"; + $params = array(); + + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBar'); + + while ($dao->fetch()) { + $con_page[$dao->id] = array(); + CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]); + //print_r($con_page[$dao->id]['starting_amount']); + + $action = array_sum(array_keys($this->actionLinks())); + //build the normal action links. + $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), + $action, + array('id' => $dao->id), + ts('more'), + TRUE + ); + } + + if (isset($con_page)) { + $this->assign('rows', $con_page); + } + +/* + $query = "SELECT * FROM civicrm_wci_progress_bar"; + $dao = CRM_Core_DAO::singleValueQuery($query); + print_r($dao); +*/ + return parent::run(); + } + +function &actionLinks() { + // check if variable _actionsLinks is populated + if (!isset(self::$_actionLinks)) { + // helper variable for nicer formatting + $deleteExtra = ts('Are you sure you want to delete this Contribution page?'); + $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?'); + + self::$_actionLinks = array( + CRM_Core_Action::UPDATE => array( + 'name' => ts('Update'), + 'url' => CRM_Utils_System::currentPath(), + 'qs' => 'action=update&reset=1&id=%%id%%', + 'title' => ts('Update'), + ), + CRM_Core_Action::DELETE => array( + 'name' => ts('Delete'), + 'url' => CRM_Utils_System::currentPath(), + 'qs' => 'action=delete&reset=1&id=%%id%%', + 'title' => ts('Delete Custom Field'), + 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', + ), + ); + } + return self::$_actionLinks; + } +} diff --git a/addmore.js b/addmore.js index 22bd5e2..870c183 100644 --- a/addmore.js +++ b/addmore.js @@ -2,33 +2,31 @@ cj(function ( $ ) { -$("#ProgressBar").validate({ - rules: { - starting_amount: { - required: true, - number: true - }, - progressbar_name: { - required: true - }, - goal_amount: { - required: true, - number: true - }, - contribution_page_1: { - required: true - }, - percentage_1: { - required: true, - max: 100, - number: true + $("#ProgressBar").validate({ + rules: { + starting_amount: { + required: true, + number: true + }, + progressbar_name: { + required: true + }, + goal_amount: { + required: true, + number: true + }, + contribution_page_1: { + required: true + }, + percentage_1: { + required: true, + max: 100, + number: true + } } - } -}); - - + }); - $('#addmore_link').on('click', function( e ) { + $('#addmore_link').on('click', function( e ) { e.preventDefault(); var count = parseInt($('input[name=contrib_count]').val()); count++; @@ -67,7 +65,7 @@ $("#ProgressBar").validate({ $('input[name=contrib_count]').val(count); -}); + }); $('#remove_link').live('click', function( e ) { e.preventDefault(); diff --git a/templates/CRM/Wci/Page/ProgressBarList.tpl b/templates/CRM/Wci/Page/ProgressBarList.tpl new file mode 100644 index 0000000..96b1918 --- /dev/null +++ b/templates/CRM/Wci/Page/ProgressBarList.tpl @@ -0,0 +1,108 @@ +{*

This new page is generated by CRM/Wci/Page/ProgressBarList.php

*} + +{* Example: Display a variable directly +

The current time is {$currentTime}

+*} +{* Example: Display a translated string -- which happens to include a variable +

{ts 1=$currentTime}(In your native language) The current time is %1.{/ts}

+*} + +{* + {capture assign=newPageURL}{crmURL p='civicrm/admin/contribute/add' q='action=add&reset=1'}{/capture} +
+ {ts}CiviContribute allows you to create and maintain any number of Online Contribution Pages. You can create different pages for different programs or campaigns - and customize text, amounts, types of information collected from contributors, etc.{/ts} {help id="id-intro"} +
+ + {include file="CRM/Contribute/Form/SearchContribution.tpl"} + {if NOT ($action eq 1 or $action eq 2) } + + + + + +
{ts}Add Contribution Page{/ts}
{ts}Manage Personal Campaign Pages{/ts} {help id="id-pcp-intro" file="CRM/PCP/Page/PCP.hlp"}
+ {/if} +*} + {if $rows} +
+ {strip} + + {include file="CRM/common/pager.tpl" location="top"} + {include file="CRM/common/pagerAToZ.tpl"} + {* handle enable/disable actions *} + {include file="CRM/common/enableDisable.tpl"} + {include file="CRM/common/jsortable.tpl"} + + + + + + {**} + {* + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + + {/if} *} + + + + {foreach from=$rows item=row} + {* class="{if NOT $row.is_active} disabled{/if}" *} + + +{* + {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))} + + {/if} *} + + + + {/foreach} +
{ts}Name{/ts}{ts}Goal Amout{/ts}{ts}Enabled?{/ts}{ts}Campaign{/ts}
{$row.name}{$row.goal_amount}{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}{$row.campaign} + + {if $row.configureActionLinks} +
+ {$row.configureActionLinks|replace:'xx':$row.id} +
+ {/if} + + {if $row.contributionLinks} +
+ {$row.contributionLinks|replace:'xx':$row.id} +
+ {/if} + + {if $row.onlineContributionLinks} +
+ {$row.onlineContributionLinks|replace:'xx':$row.id} +
+ {/if} + +
+ {$row.action|replace:'xx':$row.id} +
+ +
+ + {/strip} +
+ {else} + {if $isSearch eq 1} +
+ {ts}status{/ts} + {capture assign=browseURL}{crmURL p='civicrm/contribute/manage' q="reset=1"}{/capture} + {ts}No available Contribution Pages match your search criteria. Suggestions:{/ts} +
+ + {ts 1=$browseURL}Or you can browse all available Contribution Pages.{/ts} +
+ {else} +
+
  + {ts 1=$newPageURL}No contribution pages have been created yet. Click here to create a new contribution page.{/ts} +
+ {/if} + {/if} diff --git a/wci.php b/wci.php index da61e60..88f9a84 100644 --- a/wci.php +++ b/wci.php @@ -118,66 +118,65 @@ function wci_civicrm_navigationMenu( &$params ) { $params[$navId] = $params[$helpID]; // inserting WCI menu at the place of old help location $params[$helpID] = array ( - 'attributes' => array ( - 'label' => ts('WCI'), - 'name' => 'WCI', - 'url' => null, - 'permission' => 'access CiviReport,access CiviContribute', - 'operator' => 'OR', - 'separator' => 0, - 'parentID' => 0, - 'navID' => $navId, - 'active' => 1), - 'child' => array ( - '1' => array ( - 'attributes' => array ( - 'label' => ts('New widget'), - 'name' => 'new_widget', - 'url' => 'civicrm/wci/widget/add', - 'permission' => 'access CiviReport,access CiviContribute', - 'operator' => 'OR', - 'separator' => 1, - 'parentID' => navId, - 'navID' => $navId+1, - 'active' => 1)), - - '2' => array ( - 'attributes' => array ( - 'label' => ts('Manage widget'), - 'name' => 'manage_widget', - 'url' => 'civicrm/wci/widget', - 'permission' => 'access CiviReport,access CiviContribute', - 'operator' => 'OR', - 'separator' => 1, - 'parentID' => navId, - 'navID' => $navId+2, - 'active' => 1)), - - '3' => array ( - 'attributes' => array ( - 'label' => ts('New Progress bar'), - 'name' => 'new_progress_bar', - 'url' => 'civicrm/wci/progress-bar/add', - 'permission' => 'access CiviReport,access CiviContribute', - 'operator' => 'OR', - 'separator' => 1, - 'parentID' => navId, - 'navID' => $navId+3, - 'active' => 1)), - - '4' => array ( - 'attributes' => array ( - 'label' => ts('Manage Progress bar'), - 'name' => 'manage_progress_bar', - 'url' => 'civicrm/wci/progress-bar', - 'permission' => 'access CiviReport,access CiviContribute', - 'operator' => 'OR', - 'separator' => 1, - 'parentID' => navId, - 'navID' => $navId+4, - 'active' => 1)), - ), - + 'attributes' => array ( + 'label' => ts('WCI'), + 'name' => 'WCI', + 'url' => null, + 'permission' => 'access CiviReport,access CiviContribute', + 'operator' => 'OR', + 'separator' => 0, + 'parentID' => 0, + 'navID' => $navId, + 'active' => 1), + 'child' => array ( + '1' => array ( + 'attributes' => array ( + 'label' => ts('New widget'), + 'name' => 'new_widget', + 'url' => 'civicrm/wci/widget/add', + 'permission' => 'access CiviReport,access CiviContribute', + 'operator' => 'OR', + 'separator' => 1, + 'parentID' => navId, + 'navID' => $navId+1, + 'active' => 1)), + + '2' => array ( + 'attributes' => array ( + 'label' => ts('Manage widget'), + 'name' => 'manage_widget', + 'url' => 'civicrm/wci/widget', + 'permission' => 'access CiviReport,access CiviContribute', + 'operator' => 'OR', + 'separator' => 1, + 'parentID' => navId, + 'navID' => $navId+2, + 'active' => 1)), + + '3' => array ( + 'attributes' => array ( + 'label' => ts('New Progress bar'), + 'name' => 'new_progress_bar', + 'url' => 'civicrm/wci/progress-bar/add', + 'permission' => 'access CiviReport,access CiviContribute', + 'operator' => 'OR', + 'separator' => 1, + 'parentID' => navId, + 'navID' => $navId+3, + 'active' => 1)), + + '4' => array ( + 'attributes' => array ( + 'label' => ts('Manage Progress bar'), + 'name' => 'manage_progress_bar', + 'url' => 'civicrm/wci/progress-bar', + 'permission' => 'access CiviReport,access CiviContribute', + 'operator' => 'OR', + 'separator' => 1, + 'parentID' => navId, + 'navID' => $navId+4, + 'active' => 1)), + ), ); } diff --git a/xml/Menu/wci.xml b/xml/Menu/wci.xml index 0098354..f8048a3 100644 --- a/xml/Menu/wci.xml +++ b/xml/Menu/wci.xml @@ -18,4 +18,10 @@ TestBar access CiviCRM + + civicrm/wci/progress-bar + CRM_Wci_Page_ProgressBarList + ProgressBarList + access CiviCRM + -- 2.25.1