fixed beta 1 bugs, 31062, 31063, 31101, 31067, 31065
[com.zyxware.civiwci.git] / CRM / Wci / Page / ProgressBarList.php
CommitLineData
cde51233
J
1<?php
2
3require_once 'CRM/Core/Page.php';
4require_once 'CRM/Wci/DAO/ProgressBar.php';
5
6class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page {
7 private static $_actionLinks;
8 function run() {
9 // get the requested action
10 $action = CRM_Utils_Request::retrieve('action', 'String',
11 // default to 'browse'
12 $this, FALSE, 'browse'
13 );
cde51233
J
14 // assign vars to templates
15 $this->assign('action', $action);
16 $id = CRM_Utils_Request::retrieve('id', 'Positive',
17 $this, FALSE, 0
18 );
19
cde51233 20 if ($action & CRM_Core_Action::UPDATE) {
cde51233
J
21 $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar',
22 'Edit Progressbar',
23 CRM_Core_Action::UPDATE
24 );
25 $controller->set('id', $id);
26 $controller->process();
27 return $controller->run();
10119db1
J
28 }
29 elseif ($action & CRM_Core_Action::DELETE) {
fbe9a7d4 30 $errorScope = CRM_Core_TemporaryErrorScope::useException();
abcb1117
J
31 try {
32 $transaction = new CRM_Core_Transaction();
33 $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = " . $id;
34 CRM_Core_DAO::executeQuery($sql);
35
36 $sql = "DELETE FROM civicrm_wci_progress_bar where id = " . $id;
37 CRM_Core_DAO::executeQuery($sql);
38 $transaction->commit();
39 }
40 catch (Exception $e) {
fbe9a7d4
J
41 $errmgs = $e->getMessage() . ts('. Check whether progressbar is used by any widget or not');
42 CRM_Core_Session::setStatus($errmgs, '', 'error');
abcb1117
J
43 $transaction->rollback();
44 }
45 }
cde51233 46 // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
540f6530 47 CRM_Utils_System::setTitle(ts('Progress Bar List'));
cde51233 48
cde51233
J
49 $query = "SELECT * FROM civicrm_wci_progress_bar";
50 $params = array();
51
e364fc74 52 $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar');
cde51233
J
53
54 while ($dao->fetch()) {
55 $con_page[$dao->id] = array();
56 CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
abcb1117 57
cde51233
J
58 $action = array_sum(array_keys($this->actionLinks()));
59 //build the normal action links.
60 $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(),
61 $action,
62 array('id' => $dao->id),
63 ts('more'),
64 TRUE
65 );
66 }
67
68 if (isset($con_page)) {
69 $this->assign('rows', $con_page);
70 }
cde51233
J
71 return parent::run();
72 }
73
ca0dca6f 74 function &actionLinks() {
cde51233
J
75 // check if variable _actionsLinks is populated
76 if (!isset(self::$_actionLinks)) {
77 // helper variable for nicer formatting
abcb1117 78 $deleteExtra = ts('Are you sure you want to delete this Progressbar page?');
cde51233
J
79
80 self::$_actionLinks = array(
81 CRM_Core_Action::UPDATE => array(
540f6530 82 'name' => ts('Edit'),
cde51233
J
83 'url' => CRM_Utils_System::currentPath(),
84 'qs' => 'action=update&reset=1&id=%%id%%',
85 'title' => ts('Update'),
86 ),
87 CRM_Core_Action::DELETE => array(
88 'name' => ts('Delete'),
89 'url' => CRM_Utils_System::currentPath(),
90 'qs' => 'action=delete&reset=1&id=%%id%%',
91 'title' => ts('Delete Custom Field'),
92 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
93 ),
94 );
95 }
96 return self::$_actionLinks;
97 }
98}