From: Jagadedes Date: Thu, 9 Oct 2014 09:25:58 +0000 (+0530) Subject: #29758 Widget listing page X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ca0dca6f08472fc39f8c6158f1dd1d254e758e24;p=com.zyxware.civiwci.git #29758 Widget listing page --- diff --git a/CRM/Wci/Form/CreateWidget.php b/CRM/Wci/Form/CreateWidget.php index 8570d72..c69796b 100644 --- a/CRM/Wci/Form/CreateWidget.php +++ b/CRM/Wci/Form/CreateWidget.php @@ -6,19 +6,18 @@ require_once 'CRM/Wci/BAO/ProgressBar.php'; ?> @@ -40,12 +39,8 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { function preProcess() { parent::preProcess(); - -// CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.wci', 'tpl-state.js'); - - $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', - $this, FALSE, NULL, 'REQUEST' - ); + $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, + FALSE, NULL, 'REQUEST' ); $this->_colorFields = array('color_title' => array(ts('Title Text Color'), 'text', @@ -139,42 +134,134 @@ class CRM_Wci_Form_CreateWidget extends CRM_Core_Form { // export form elements $this->assign('elementNames', $this->getRenderableElementNames()); - + $smarty = CRM_Core_Smarty::singleton(); - /** Keep template in civicrm-wci/templates folder*/ - $output = $smarty->fetch('Widget.tpl'); - $elem = $this->getElement('custom_template'); - $elem->setValue($output); + if (isset($this->_id)) { + /** Updating existing widget*/ + + //$query = "SELECT * FROM civicrm_wci_widget where id=" . $this->_id; + $query = "SELECT pb.id as pbid, w.* FROM civicrm_wci_widget w INNER JOIN civicrm_wci_progress_bar pb on pb.id = w.progress_bar_id +where w.id=" . $this->_id; + $params = array(); + + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_Widget'); + + while ($dao->fetch()) { + $wid_page[$dao->id] = array(); + CRM_Core_DAO::storeValues($dao, $wid_page[$dao->id]); + + $this->setDefaults(array( + 'title' => $wid_page[$dao->id]['title'])); + $this->setDefaults(array( + 'logo_image' => $wid_page[$dao->id]['logo_image'])); + $this->setDefaults(array( + 'image' => $wid_page[$dao->id]['image'])); + $this->setDefaults(array( + 'button_link_to' => $wid_page[$dao->id]['button_link_to'])); + $this->setDefaults(array( + 'button_title' => $wid_page[$dao->id]['button_title'])); + + $this->setDefaults(array( + 'progress_bar' => $dao->pbid)); + $description = base64_decode($wid_page[$dao->id]['description']); + $this->setDefaults(array( + 'description' => $description)); + $this->setDefaults(array( + 'email_signup_group_id' => $wid_page[$dao->id]['email_signup_group_id'])); + $this->setDefaults(array( + 'size_variant' => $wid_page[$dao->id]['size_variant'])); + $this->setDefaults(array( + 'color_title' => $wid_page[$dao->id]['color_title'])); + $this->setDefaults(array( + 'color_title_bg' => $wid_page[$dao->id]['color_title_bg'])); + $this->setDefaults(array( + 'color_bar' => $wid_page[$dao->id]['color_progress_bar'])); + $this->setDefaults(array( + 'color_widget_bg' => $wid_page[$dao->id]['color_widget_bg'])); + $this->setDefaults(array( + 'color_description' => $wid_page[$dao->id]['color_description'])); + $this->setDefaults(array( + 'color_border' => $wid_page[$dao->id]['color_border'])); + $this->setDefaults(array( + 'color_button' => $wid_page[$dao->id]['color_button'])); + $this->setDefaults(array( + 'color_button_bg' => $wid_page[$dao->id]['color_button_bg'])); + $this->setDefaults(array( + 'style_rules' => $wid_page[$dao->id]['style_rules'])); + $this->setDefaults(array( + 'override' => $wid_page[$dao->id]['override'])); + $cust_templ = base64_decode($wid_page[$dao->id]['custom_template']); + + $this->setDefaults(array( + 'custom_template' => $cust_templ)); + } + } + else { + /** Keep template in civicrm-wci/templates folder*/ + $output = $smarty->fetch('Widget.tpl'); + $output = file_get_contents('sites/all/modules/civicrm/extensions/civicrm-wci/templates/Widget.tpl'); + $elem = $this->getElement('custom_template'); + $elem->setValue($output); + } parent::buildQuickForm(); } function postProcess() { - $values = $this->exportValues(); $override = 0; + $cust_tmpl = ""; + $cust_tmpl_col = ""; + $sql = ""; + /** If override check is checked state then only save the custom_template to the + database. otherwise wci uses default tpl file. + */ if(isset($values['override'])){ $override = $values['override']; + $cust_tmpl = base64_encode(html_entity_decode($values['custom_template'])); + $cust_tmpl_col = ", custom_template"; } - - $sql = "INSERT INTO civicrm_wci_widget (title, logo_image, image, - button_title, button_link_to, progress_bar_id, description, - email_signup_group_id, size_variant, color_title, color_title_bg, - color_progress_bar, color_widget_bg, color_description, color_border, - color_button, color_button_bg, style_rules, override, custom_template ) - VALUES ('" . $values['title'] . "','" . $values['logo_image'] . "','" . - $values['image'] . "','" . $values['button_title'] . "','" . - $values['button_link_to'] . "','" . $values['progress_bar'] . "','" . - base64_encode($values['description']) . "','" . - $values['email_signup_group_id'] . "','" . - $values['size_variant'] . "','" . $values['color_title'] . "','" . - $values['color_title_bg'] . "','" . $values['color_bar'] . "','" . - $values['color_widget_bg'] . "','" . $values['color_description'] . "','" . - $values['color_border'] . "','" . $values['color_button'] . "','" . - $values['color_button_bg'] . "','" . $values['style_rules'] . "','" . - $override . "','" . base64_encode($values['custom_template']) - . "')"; + if (isset($this->_id)) { + $cust_tmpl_col = "'" . $cust_tmpl_col . "='"; + $sql = "UPDATE civicrm_wci_widget SET title = '". $values['title'] + . "', logo_image = '" . $values['logo_image'] . "', image = '" + . $values['image'] . "', button_title = '" . $values['button_title'] + . "', button_link_to = '" . $values['button_link_to'] + . "', progress_bar_id = '" . $values['progress_bar'] + . "', description = '" . base64_encode($values['description']) + . "', email_signup_group_id = '" . $values['email_signup_group_id'] + . "', size_variant = '" . $values['size_variant'] + . "', color_title = '" . $values['color_title'] + . "', color_title_bg = '" . $values['color_title_bg'] + . "', color_progress_bar = '" . $values['color_bar'] + . "', color_widget_bg = '" . $values['color_widget_bg'] + . "', color_description = '" . $values['color_description'] + . "', color_border = '" . $values['color_border'] + . "', color_button = '" . $values['color_button'] + . "', color_button_bg = '" . $values['color_button_bg'] + . "', style_rules = '" . $values['style_rules'] . "', override = '" + . $override . $cust_tmpl_col . $cust_tmpl . "'"; + } + else { + $sql = "INSERT INTO civicrm_wci_widget (title, logo_image, image, + button_title, button_link_to, progress_bar_id, description, + email_signup_group_id, size_variant, color_title, color_title_bg, + color_progress_bar, color_widget_bg, color_description, color_border, + color_button, color_button_bg, style_rules, override" . $cust_tmpl_col ." ) + VALUES ('" . $values['title'] . "','" . $values['logo_image'] . "','" . + $values['image'] . "','" . $values['button_title'] . "','" . + $values['button_link_to'] . "','" . $values['progress_bar'] . "','" . + base64_encode($values['description']) . "','" . + $values['email_signup_group_id'] . "','" . + $values['size_variant'] . "','" . $values['color_title'] . "','" . + $values['color_title_bg'] . "','" . $values['color_bar'] . "','" . + $values['color_widget_bg'] . "','" . $values['color_description'] . "','" . + $values['color_border'] . "','" . $values['color_button'] . "','" . + $values['color_button_bg'] . "','" . $values['style_rules'] . "','" . + $override . "','" . $cust_tmpl + . "')"; + } $errorScope = CRM_Core_TemporaryErrorScope::useException(); try { $transaction = new CRM_Core_Transaction(); diff --git a/CRM/Wci/Page/ProgressBarList.php b/CRM/Wci/Page/ProgressBarList.php index c225821..3b2454d 100644 --- a/CRM/Wci/Page/ProgressBarList.php +++ b/CRM/Wci/Page/ProgressBarList.php @@ -45,9 +45,6 @@ class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page { // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml CRM_Utils_System::setTitle(ts('ProgressBarList')); - // Example: Assign a variable for use in a template - $this->assign('currentTime', date('Y-m-d H:i:s')); - $query = "SELECT * FROM civicrm_wci_progress_bar"; $params = array(); @@ -73,7 +70,7 @@ class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page { return parent::run(); } -function &actionLinks() { + function &actionLinks() { // check if variable _actionsLinks is populated if (!isset(self::$_actionLinks)) { // helper variable for nicer formatting diff --git a/CRM/Wci/Page/WidgetList.php b/CRM/Wci/Page/WidgetList.php new file mode 100644 index 0000000..2a9d8af --- /dev/null +++ b/CRM/Wci/Page/WidgetList.php @@ -0,0 +1,97 @@ +assign('action', $action); + $id = CRM_Utils_Request::retrieve('id', 'Positive', + $this, FALSE, 0 + ); + + if ($action & CRM_Core_Action::UPDATE) { + $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_CreateWidget', + 'Edit Widget', + CRM_Core_Action::UPDATE + ); + $controller->set('id', $id); + $controller->process(); + return $controller->run(); + } + elseif ($action & CRM_Core_Action::DELETE) { + try { + $transaction = new CRM_Core_Transaction(); + + $sql = "DELETE FROM civicrm_wci_widget where id = " . $id; + CRM_Core_DAO::executeQuery($sql); + $transaction->commit(); + } + catch (Exception $e) { + //TODO + print_r($e->getMessage()); + $transaction->rollback(); + } + } + + CRM_Utils_System::setTitle(ts('Widget List')); + $query = "SELECT * FROM civicrm_wci_widget"; + $params = array(); + + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_Widget'); + + while ($dao->fetch()) { + $wid_page[$dao->id] = array(); + CRM_Core_DAO::storeValues($dao, $wid_page[$dao->id]); + $description = base64_decode($wid_page[$dao->id]['description']); + $wid_page[$dao->id]['description'] = strip_tags($description); + + $action = array_sum(array_keys($this->actionLinks())); + //build the normal action links. + $wid_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), + $action, + array('id' => $dao->id), + ts('more'), + TRUE + ); + } + + if (isset($wid_page)) { + $this->assign('rows', $wid_page); + } + + parent::run(); + } + + function &actionLinks() { + // check if variable _actionsLinks is populated + if (!isset(self::$_actionLinks)) { + // helper variable for nicer formatting + $deleteExtra = ts('Are you sure you want to delete this Widget?'); + + self::$_actionLinks = array( + CRM_Core_Action::UPDATE => array( + 'name' => ts('Update'), + 'url' => CRM_Utils_System::currentPath(), + 'qs' => 'action=update&reset=1&id=%%id%%', + 'title' => ts('Update'), + ), + CRM_Core_Action::DELETE => array( + 'name' => ts('Delete'), + 'url' => CRM_Utils_System::currentPath(), + 'qs' => 'action=delete&reset=1&id=%%id%%', + 'title' => ts('Delete Custom Field'), + 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', + ), + ); + } + return self::$_actionLinks; + } +} diff --git a/wci.php b/wci.php index 005b1f8..8ad8118 100644 --- a/wci.php +++ b/wci.php @@ -145,7 +145,7 @@ function wci_civicrm_navigationMenu( &$params ) { 'attributes' => array ( 'label' => ts('Manage widget'), 'name' => 'manage_widget', - 'url' => 'civicrm/wci/widget', + 'url' => 'civicrm/wci/widget?reset=1', 'permission' => 'access CiviReport,access CiviContribute', 'operator' => 'OR', 'separator' => 1, diff --git a/xml/Menu/wci.xml b/xml/Menu/wci.xml index f8048a3..f606843 100644 --- a/xml/Menu/wci.xml +++ b/xml/Menu/wci.xml @@ -24,4 +24,10 @@ ProgressBarList access CiviCRM + + civicrm/wci/widget + CRM_Wci_Page_WidgetList + Widget List + access CiviCRM +