Handle the case where there is no embed code id in the embed code
[com.zyxware.civiwci.git] / CRM / Wci / Page / ProgressBarList.php
CommitLineData
cde51233 1<?php
bccdda02
J
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM Widget Creation Interface (WCI) Version 1.0 |
5 +--------------------------------------------------------------------+
6 | Copyright Zyxware Technologies (c) 2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM WCI. |
9 | |
10 | CiviCRM WCI is free software; you can copy, modify, and distribute |
11 | it under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
13 | |
14 | CiviCRM WCI is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact Zyxware |
21 | Technologies at info[AT]zyxware[DOT]com. |
22 +--------------------------------------------------------------------+
23*/
cde51233
J
24require_once 'CRM/Core/Page.php';
25require_once 'CRM/Wci/DAO/ProgressBar.php';
26
27class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page {
28 private static $_actionLinks;
bccdda02 29
cde51233
J
30 function run() {
31 // get the requested action
32 $action = CRM_Utils_Request::retrieve('action', 'String',
33 // default to 'browse'
34 $this, FALSE, 'browse'
35 );
cde51233
J
36 // assign vars to templates
37 $this->assign('action', $action);
38 $id = CRM_Utils_Request::retrieve('id', 'Positive',
39 $this, FALSE, 0
40 );
41
cde51233 42 if ($action & CRM_Core_Action::UPDATE) {
cde51233
J
43 $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar',
44 'Edit Progressbar',
45 CRM_Core_Action::UPDATE
46 );
47 $controller->set('id', $id);
48 $controller->process();
49 return $controller->run();
bccdda02 50 }
10119db1 51 elseif ($action & CRM_Core_Action::DELETE) {
fbe9a7d4 52 $errorScope = CRM_Core_TemporaryErrorScope::useException();
abcb1117
J
53 try {
54 $transaction = new CRM_Core_Transaction();
b3e303a2
J
55 $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = %1";
56 $params = array(1 => array($id, 'Integer'));
57 CRM_Core_DAO::executeQuery($sql, $params);
bccdda02 58
b3e303a2
J
59 $sql = "DELETE FROM civicrm_wci_progress_bar where id = %1";
60 $params = array(1 => array($id, 'Integer'));
61 CRM_Core_DAO::executeQuery($sql, $params);
abcb1117
J
62 $transaction->commit();
63 }
64 catch (Exception $e) {
fbe9a7d4
J
65 $errmgs = $e->getMessage() . ts('. Check whether progressbar is used by any widget or not');
66 CRM_Core_Session::setStatus($errmgs, '', 'error');
bccdda02
J
67 $transaction->rollback();
68 }
abcb1117 69 }
cde51233 70 // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
540f6530 71 CRM_Utils_System::setTitle(ts('Progress Bar List'));
cde51233 72
cde51233
J
73 $query = "SELECT * FROM civicrm_wci_progress_bar";
74 $params = array();
bccdda02 75
e364fc74 76 $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
cde51233
J
77
78 while ($dao->fetch()) {
79 $con_page[$dao->id] = array();
80 CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
bccdda02
J
81
82 $action = array_sum(array_keys($this->actionLinks()));
cde51233
J
83 //build the normal action links.
84 $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(),
9e2703a2 85 $action, array('id' => $dao->id));
cde51233
J
86 }
87
88 if (isset($con_page)) {
89 $this->assign('rows', $con_page);
90 }
cde51233
J
91 return parent::run();
92 }
bccdda02 93
ca0dca6f 94 function &actionLinks() {
cde51233
J
95 // check if variable _actionsLinks is populated
96 if (!isset(self::$_actionLinks)) {
97 // helper variable for nicer formatting
abcb1117 98 $deleteExtra = ts('Are you sure you want to delete this Progressbar page?');
cde51233
J
99
100 self::$_actionLinks = array(
101 CRM_Core_Action::UPDATE => array(
540f6530 102 'name' => ts('Edit'),
cde51233
J
103 'url' => CRM_Utils_System::currentPath(),
104 'qs' => 'action=update&reset=1&id=%%id%%',
105 'title' => ts('Update'),
106 ),
107 CRM_Core_Action::DELETE => array(
108 'name' => ts('Delete'),
109 'url' => CRM_Utils_System::currentPath(),
110 'qs' => 'action=delete&reset=1&id=%%id%%',
111 'title' => ts('Delete Custom Field'),
112 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
113 ),
114 );
115 }
116 return self::$_actionLinks;
117 }
118}