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