progressbar listing page
authorJagadedes <jagadees.pillai@zyxware.com>
Tue, 30 Sep 2014 12:17:03 +0000 (17:47 +0530)
committerJagadedes <jagadees.pillai@zyxware.com>
Tue, 30 Sep 2014 12:17:03 +0000 (17:47 +0530)
CRM/Wci/Form/ProgressBar.php
CRM/Wci/Page/ProgressBarList.php [new file with mode: 0644]
addmore.js
templates/CRM/Wci/Page/ProgressBarList.tpl [new file with mode: 0644]
wci.php
xml/Menu/wci.xml

index 0992e9ecc0b3d3769a88cbea1acd183e8190e7a9..9d84ccecab42e6d4d66b7fc19056fbb1e3147981 100644 (file)
@@ -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 . '<br>';
+      $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 (file)
index 0000000..e9f9716
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+
+require_once 'CRM/Core/Page.php';
+require_once 'CRM/Wci/DAO/ProgressBar.php';
+
+class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page {
+  private static $_actionLinks;
+  function run() {
+    // get the requested action
+    $action = CRM_Utils_Request::retrieve('action', 'String',
+      // default to 'browse'
+      $this, FALSE, 'browse'
+    );
+    echo $action;
+    // assign vars to templates
+    $this->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;
+  }
+}
index 22bd5e20ec6b072d572a822a59d853b8aa82e03a..870c18376eab07cf2d733908744a6422972464cc 100644 (file)
@@ -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 (file)
index 0000000..96b1918
--- /dev/null
@@ -0,0 +1,108 @@
+{*<h3>This new page is generated by CRM/Wci/Page/ProgressBarList.php</h3> *}
+
+{* Example: Display a variable directly 
+<p>The current time is {$currentTime}</p>
+*}
+{* Example: Display a translated string -- which happens to include a variable 
+<p>{ts 1=$currentTime}(In your native language) The current time is %1.{/ts}</p>
+*}
+
+{*
+    {capture assign=newPageURL}{crmURL p='civicrm/admin/contribute/add' q='action=add&reset=1'}{/capture}
+    <div id="help">
+       {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"}
+    </div>
+
+    {include file="CRM/Contribute/Form/SearchContribution.tpl"}
+    {if NOT ($action eq 1 or $action eq 2) }
+      <table class="form-layout-compressed">
+      <tr>
+      <td><a href="{$newPageURL}" class="button"><span><div class="icon add-icon"></div>{ts}Add Contribution Page{/ts}</span></a></td>
+            <td style="vertical-align: top"><a class="button" href="{crmURL p="civicrm/admin/pcp" q="reset=1"}"><span>{ts}Manage Personal Campaign Pages{/ts}</span></a> {help id="id-pcp-intro" file="CRM/PCP/Page/PCP.hlp"}</td>
+      </tr>
+      </table>
+    {/if}
+*}
+    {if $rows}
+      <div id="configure_contribution_page">
+             {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"}
+             <table id="options" class="display">
+               <thead>
+               <tr>
+                 <th id="sortable">{ts}Name{/ts}</th>
+               <th>{ts}Goal Amout{/ts}</th>
+               {*<th>{ts}Enabled?{/ts}</th>*}
+               {*
+             {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))}
+             <th>{ts}Campaign{/ts}</th>
+            {/if} *}
+            <th></th>
+               </tr>
+               </thead>
+               {foreach from=$rows item=row}
+                 <tr id="row_{$row.id}" >   {* class="{if NOT $row.is_active} disabled{/if}" *}
+                     <td><strong>{$row.name}</strong></td>
+                     <td>{$row.goal_amount}</td>
+{*                     <td id="row_{$row.id}_status">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
+          {if call_user_func(array('CRM_Campaign_BAO_Campaign','isCampaignEnable'))}
+          <td>{$row.campaign}</td> 
+          {/if} *}
+          <td class="crm-contribution-page-actions right nowrap">
+
+       {if $row.configureActionLinks}
+         <div class="crm-contribution-page-configure-actions">
+                  {$row.configureActionLinks|replace:'xx':$row.id}
+         </div>
+             {/if}
+
+            {if $row.contributionLinks}
+        <div class="crm-contribution-online-contribution-actions">
+                  {$row.contributionLinks|replace:'xx':$row.id}
+        </div>
+        {/if}
+
+        {if $row.onlineContributionLinks}
+        <div class="crm-contribution-search-contribution-actions">
+                  {$row.onlineContributionLinks|replace:'xx':$row.id}
+        </div>
+        {/if}
+
+        <div class="crm-contribution-page-more">
+                    {$row.action|replace:'xx':$row.id}
+            </div>
+
+      </td>
+
+         </tr>
+         {/foreach}
+      </table>
+
+        {/strip}
+      </div>
+    {else}
+  {if $isSearch eq 1}
+      <div class="status messages">
+                <img src="{$config->resourceBase}i/Inform.gif" alt="{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}
+                    <div class="spacer"></div>
+                    <ul>
+                    <li>{ts}Check your spelling.{/ts}</li>
+                    <li>{ts}Try a different spelling or use fewer letters.{/ts}</li>
+                    <li>{ts}Make sure you have enough privileges in the access control system.{/ts}</li>
+                    </ul>
+                    {ts 1=$browseURL}Or you can <a href='%1'>browse all available Contribution Pages</a>.{/ts}
+      </div>
+      {else}
+      <div class="messages status no-popup">
+             <div class="icon inform-icon"></div> &nbsp;
+             {ts 1=$newPageURL}No contribution pages have been created yet. Click <a accesskey="N" href='%1'>here</a> to create a new contribution page.{/ts}
+      </div>
+        {/if}
+    {/if}
diff --git a/wci.php b/wci.php
index da61e60d362f4483c651bc94e75baf4c219bdbc4..88f9a84c6c47deb99defd38cea4cf0867728189c 100644 (file)
--- 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)),           
+        ),
   );
 }
 
index 0098354053b40476215177c870140ce06b9432a6..f8048a3c10fdea5a8422b7d3a34140440076d597 100644 (file)
     <title>TestBar</title>
     <access_arguments>access CiviCRM</access_arguments>
   </item>
+  <item>
+    <path>civicrm/wci/progress-bar</path>
+    <page_callback>CRM_Wci_Page_ProgressBarList</page_callback>
+    <title>ProgressBarList</title>
+    <access_arguments>access CiviCRM</access_arguments>
+  </item>
 </menu>