Commit | Line | Data |
---|---|---|
cde51233 J |
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 | ); | |
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) { | |
abcb1117 J |
30 | try { |
31 | $transaction = new CRM_Core_Transaction(); | |
32 | $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = " . $id; | |
33 | CRM_Core_DAO::executeQuery($sql); | |
34 | ||
35 | $sql = "DELETE FROM civicrm_wci_progress_bar where id = " . $id; | |
36 | CRM_Core_DAO::executeQuery($sql); | |
37 | $transaction->commit(); | |
38 | } | |
39 | catch (Exception $e) { | |
40 | //TODO | |
41 | print_r($e->getMessage()); | |
42 | $transaction->rollback(); | |
43 | } | |
44 | } | |
cde51233 | 45 | // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml |
540f6530 | 46 | CRM_Utils_System::setTitle(ts('Progress Bar List')); |
cde51233 | 47 | |
cde51233 J |
48 | $query = "SELECT * FROM civicrm_wci_progress_bar"; |
49 | $params = array(); | |
50 | ||
e364fc74 | 51 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBar'); |
cde51233 J |
52 | |
53 | while ($dao->fetch()) { | |
54 | $con_page[$dao->id] = array(); | |
55 | CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]); | |
abcb1117 | 56 | |
cde51233 J |
57 | $action = array_sum(array_keys($this->actionLinks())); |
58 | //build the normal action links. | |
59 | $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), | |
60 | $action, | |
61 | array('id' => $dao->id), | |
62 | ts('more'), | |
63 | TRUE | |
64 | ); | |
65 | } | |
66 | ||
67 | if (isset($con_page)) { | |
68 | $this->assign('rows', $con_page); | |
69 | } | |
cde51233 J |
70 | return parent::run(); |
71 | } | |
72 | ||
ca0dca6f | 73 | function &actionLinks() { |
cde51233 J |
74 | // check if variable _actionsLinks is populated |
75 | if (!isset(self::$_actionLinks)) { | |
76 | // helper variable for nicer formatting | |
abcb1117 | 77 | $deleteExtra = ts('Are you sure you want to delete this Progressbar page?'); |
cde51233 J |
78 | |
79 | self::$_actionLinks = array( | |
80 | CRM_Core_Action::UPDATE => array( | |
540f6530 | 81 | 'name' => ts('Edit'), |
cde51233 J |
82 | 'url' => CRM_Utils_System::currentPath(), |
83 | 'qs' => 'action=update&reset=1&id=%%id%%', | |
84 | 'title' => ts('Update'), | |
85 | ), | |
86 | CRM_Core_Action::DELETE => array( | |
87 | 'name' => ts('Delete'), | |
88 | 'url' => CRM_Utils_System::currentPath(), | |
89 | 'qs' => 'action=delete&reset=1&id=%%id%%', | |
90 | 'title' => ts('Delete Custom Field'), | |
91 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', | |
92 | ), | |
93 | ); | |
94 | } | |
95 | return self::$_actionLinks; | |
96 | } | |
97 | } |