?>
<script type="text/javascript">
-cj(function ( $ ) {
- $(document).ready(function(){
- $('#custom_template').attr("disabled",true);
- });
-
- $('#override').on('click', function( e ) {
+cj(function ( $ ) {
+ function setState() {
if ($('#override').is(':checked') == true) {
$('#custom_template').attr("disabled",false);
}
else {
$('#custom_template').attr("disabled",true);
- }
- });
+ }
+ }
+ $(document).ready(setState)
+ $('#override').click(setState);
+
});
</script>
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',
// 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();
--- /dev/null
+<?php
+
+require_once 'CRM/Core/Page.php';
+require_once 'CRM/Wci/DAO/Widget.php';
+
+class CRM_Wci_Page_WidgetList extends CRM_Core_Page {
+ private static $_actionLinks;
+ function run() {
+ // get the requested action
+ $action = CRM_Utils_Request::retrieve('action', 'String',
+ // default to 'browse'
+ $this, FALSE, 'browse'
+ );
+ // assign vars to templates
+ $this->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;
+ }
+}