Fix text in the embed code license
[com.zyxware.civiwci.git] / CRM / Wci / Page / WidgetList.php
1 <?php
2 /*
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. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
23 */
24 require_once 'CRM/Core/Page.php';
25 require_once 'CRM/Wci/DAO/Widget.php';
26
27 class CRM_Wci_Page_WidgetList extends CRM_Core_Page {
28 private static $_actionLinks;
29
30 function run() {
31 // get the requested action
32 $action = CRM_Utils_Request::retrieve('action', 'String',
33 // default to 'browse'
34 $this, FALSE, 'browse'
35 );
36 // assign vars to templates
37 $this->assign('action', $action);
38 $id = CRM_Utils_Request::retrieve('id', 'Positive',
39 $this, FALSE, 0
40 );
41
42 if ($action & CRM_Core_Action::UPDATE) {
43 $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_CreateWidget',
44 'Edit Widget',
45 CRM_Core_Action::UPDATE
46 );
47 $controller->set('id', $id);
48 $controller->process();
49 return $controller->run();
50 }
51 elseif ($action & CRM_Core_Action::DELETE) {
52 try {
53 $transaction = new CRM_Core_Transaction();
54
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();
59 }
60 catch (Exception $e) {
61 CRM_Core_Session::setStatus(ts('Failed to delete widget. ') . $e->getMessage(), '', 'error');
62 $transaction->rollback();
63 }
64 }
65
66 CRM_Utils_System::setTitle(ts('Widget List'));
67 $query = "SELECT * FROM civicrm_wci_widget";
68 $params = array();
69
70 $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_Widget');
71
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);
78
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));
83 }
84
85 if (isset($wid_page)) {
86 $this->assign('rows', $wid_page);
87 }
88
89 parent::run();
90 }
91
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?');
97
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'),
104 ),
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 . '\');"',
111 ),
112 );
113 }
114 return self::$_actionLinks;
115 }
116 }