Commit | Line | Data |
---|---|---|
ca0dca6f J |
1 | <?php |
2 | ||
3 | require_once 'CRM/Core/Page.php'; | |
4 | require_once 'CRM/Wci/DAO/Widget.php'; | |
5 | ||
6 | class CRM_Wci_Page_WidgetList 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_CreateWidget', | |
22 | 'Edit Widget', | |
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 | try { | |
31 | $transaction = new CRM_Core_Transaction(); | |
32 | ||
33 | $sql = "DELETE FROM civicrm_wci_widget where id = " . $id; | |
34 | CRM_Core_DAO::executeQuery($sql); | |
35 | $transaction->commit(); | |
36 | } | |
37 | catch (Exception $e) { | |
38 | //TODO | |
39 | print_r($e->getMessage()); | |
40 | $transaction->rollback(); | |
41 | } | |
42 | } | |
43 | ||
44 | CRM_Utils_System::setTitle(ts('Widget List')); | |
45 | $query = "SELECT * FROM civicrm_wci_widget"; | |
46 | $params = array(); | |
47 | ||
e364fc74 | 48 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget'); |
ca0dca6f J |
49 | |
50 | while ($dao->fetch()) { | |
51 | $wid_page[$dao->id] = array(); | |
52 | CRM_Core_DAO::storeValues($dao, $wid_page[$dao->id]); | |
7b653fab | 53 | $wid_page[$dao->id]['title'] = base64_decode($wid_page[$dao->id]['title']); |
ca0dca6f J |
54 | $description = base64_decode($wid_page[$dao->id]['description']); |
55 | $wid_page[$dao->id]['description'] = strip_tags($description); | |
56 | ||
57 | $action = array_sum(array_keys($this->actionLinks())); | |
58 | //build the normal action links. | |
59 | $wid_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($wid_page)) { | |
68 | $this->assign('rows', $wid_page); | |
69 | } | |
70 | ||
71 | parent::run(); | |
72 | } | |
73 | ||
74 | function &actionLinks() { | |
75 | // check if variable _actionsLinks is populated | |
76 | if (!isset(self::$_actionLinks)) { | |
77 | // helper variable for nicer formatting | |
78 | $deleteExtra = ts('Are you sure you want to delete this Widget?'); | |
79 | ||
80 | self::$_actionLinks = array( | |
81 | CRM_Core_Action::UPDATE => array( | |
540f6530 | 82 | 'name' => ts('Edit'), |
ca0dca6f 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 | } |