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. |
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. |
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. |
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 +--------------------------------------------------------------------+
24 require_once 'CRM/Core/Page.php';
25 require_once 'CRM/Wci/DAO/Widget.php';
27 class CRM_Wci_Page_WidgetList
extends CRM_Core_Page
{
28 private static $_actionLinks;
31 // get the requested action
32 $action = CRM_Utils_Request
::retrieve('action', 'String',
33 // default to 'browse'
34 $this, FALSE, 'browse'
36 // assign vars to templates
37 $this->assign('action', $action);
38 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
42 if ($action & CRM_Core_Action
::UPDATE
) {
43 $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_CreateWidget',
45 CRM_Core_Action
::UPDATE
47 $controller->set('id', $id);
48 $controller->process();
49 return $controller->run();
51 elseif ($action & CRM_Core_Action
::DELETE
) {
53 $transaction = new CRM_Core_Transaction();
55 $sql = "DELETE FROM civicrm_wci_widget where id = %1";
56 $params = array(1 => array($id, 'Integer'));
57 CRM_Core_DAO
::executeQuery($sql, $params);
58 $transaction->commit();
60 catch (Exception
$e) {
61 CRM_Core_Session
::setStatus(ts('Failed to delete widget. ') . $e->getMessage(), '', 'error');
62 $transaction->rollback();
66 CRM_Utils_System
::setTitle(ts('Widget List'));
67 $query = "SELECT * FROM civicrm_wci_widget";
70 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
72 while ($dao->fetch()) {
73 $wid_page[$dao->id
] = array();
74 CRM_Core_DAO
::storeValues($dao, $wid_page[$dao->id
]);
75 $wid_page[$dao->id
]['title'] = $wid_page[$dao->id
]['title'];
76 $description = $wid_page[$dao->id
]['description'];
77 $wid_page[$dao->id
]['description'] = strip_tags($description);
79 $action = array_sum(array_keys($this->actionLinks()));
80 //build the normal action links.
81 $wid_page[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(),
82 $action, array('id' => $dao->id
));
85 if (isset($wid_page)) {
86 $this->assign('rows', $wid_page);
92 function &actionLinks() {
93 // check if variable _actionsLinks is populated
94 if (!isset(self
::$_actionLinks)) {
95 // helper variable for nicer formatting
96 $deleteExtra = ts('Are you sure you want to delete this Widget?');
98 self
::$_actionLinks = array(
99 CRM_Core_Action
::UPDATE
=> array(
100 'name' => ts('Edit'),
101 'url' => CRM_Utils_System
::currentPath(),
102 'qs' => 'action=update&reset=1&id=%%id%%',
103 'title' => ts('Update'),
105 CRM_Core_Action
::DELETE
=> array(
106 'name' => ts('Delete'),
107 'url' => CRM_Utils_System
::currentPath(),
108 'qs' => 'action=delete&reset=1&id=%%id%%',
109 'title' => ts('Delete Custom Field'),
110 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
114 return self
::$_actionLinks;