static function get_widget_code($embedId, $preview = 0) { $code = ''; if ($preview) { $widget = CRM_Wci_WidgetCode::generate_widget_code($embedId, $preview); return $widget['code']; } else { $widgetId = CRM_Wci_BAO_EmbedCode::getWidgetId($embedId); $code = CRM_Wci_BAO_WidgetCache::getWidgetCache($widgetId); } if (!$code) { $widget = CRM_Wci_WidgetCode::generate_widget_code($widgetId); CRM_Wci_BAO_WidgetCache::setWidgetCache($widgetId, $widget); $code = $widget['code']; } return $code; }
function postProcess() { $values = $this->exportValues(); $override = 0; $hide_title = 0; $hide_border = 0; $hide_pbcap = 0; $cust_tmpl = ""; $cust_tmpl_col = ""; $sql = ""; $coma = ""; $equals = ""; $quote = ""; /** 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 = str_replace("'", "''", $values['custom_template']); $cust_tmpl_col = "custom_template"; $coma = ","; $equals = " = "; $quote = "'"; } if (isset($values['hide_title'])) { $hide_title = $values['hide_title']; } if (isset($values['hide_border'])) { $hide_border = $values['hide_border']; } if (isset($values['hide_pbcap'])) { $hide_pbcap = $values['hide_pbcap']; } $title = str_replace("'", "''", $values['title']); $params = array(1 => array($title, 'String'), 2 => array($values['logo_image'], 'String'), 3 => array($values['image'], 'String'), 4 => array($values['button_title'], 'String'), 5 => array($values['button_link_to'], 'String'), 6 => array($values['progress_bar'], 'Integer'), 7 => array(str_replace("'", "''", $values['description']), 'String'), 8 => array($values['email_signup_group_id'], 'String'), 9 => array($values['size_variant'], 'String'), 10 => array($values['color_title'], 'String'), 11 => array($values['color_title_bg'], 'String'), 12 => array($values['color_bar'], 'String'), 13 => array($values['color_bar_bg'], 'String'), 14 => array($values['color_widget_bg'], 'String'), 15 => array($values['color_description'], 'String'), 16 => array($values['color_border'], 'String'), 17 => array($values['color_button'], 'String'), 18 => array($values['color_button_bg'], 'String'), 19 => array($hide_title, 'Integer'), 20 => array($hide_border, 'Integer'), 21 => array($hide_pbcap, 'Integer'), 22 => array($values['color_btn_newsletter'], 'String'), 23 => array($values['color_btn_newsletter_bg'], 'String'), 24 => array($values['newsletter_text'], 'String'), 25 => array($values['color_newsletter_text'], 'String'), 26 => array($values['style_rules'], 'String'), 27 => array($override, 'Integer'), 28 => array($values['custom_template'], 'String'), 29 => array($values['show_pb_perc'], 'Integer')); if (isset($this->_id)) { $sql = "UPDATE civicrm_wci_widget SET title = %1, logo_image =%2,\n image = %3, button_title =%4, button_link_to =%5,\n progress_bar_id = %6, description = %7, email_signup_group_id = %8,\n size_variant = %9, color_title = %10, color_title_bg = %11,\n color_progress_bar = %12, color_progress_bar_bg = %13,\n color_widget_bg=%14, color_description=%15, color_border = %16,\n color_button = %17, color_button_bg = %18, hide_title = %19,\n hide_border = %20, hide_pbcap = %21, color_btn_newsletter = %22,\n color_btn_newsletter_bg = %23, newsletter_text = %24,\n color_newsletter_text = %25, style_rules = %26, override = %27,\n custom_template = %28, show_pb_perc = %29 where id = %30"; $params += array(30 => array($this->_id, 'Integer')); } else { $sql = "INSERT INTO civicrm_wci_widget (title, logo_image, image,\n button_title, button_link_to, progress_bar_id, description,\n email_signup_group_id, size_variant, color_title, color_title_bg,\n color_progress_bar, color_progress_bar_bg, color_widget_bg, color_description, color_border,\n color_button, color_button_bg, hide_title, hide_border, hide_pbcap,\n color_btn_newsletter, color_btn_newsletter_bg, newsletter_text,\n color_newsletter_text, style_rules, override, custom_template, show_pb_perc)\n VALUES (%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13,\n %14, %15, %16, %17, %18, %19, %20, %21, %22, %23, %24, %25, %26, %27, %28, %29)"; } $errorScope = CRM_Core_TemporaryErrorScope::useException(); try { $transaction = new CRM_Core_Transaction(); CRM_Core_DAO::executeQuery("SET foreign_key_checks = 0;"); CRM_Core_DAO::executeQuery($sql, $params); CRM_Core_DAO::executeQuery("SET foreign_key_checks = 1;"); $transaction->commit(); if (isset($this->_id)) { $widget_id = $this->_id; CRM_Wci_BAO_WidgetCache::deleteWidgetCache($widget_id); } else { $widget_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); } CRM_Core_Session::setStatus(ts('Widget created successfully'), '', 'success'); if (isset($_REQUEST['_qf_CreateWidget_next'])) { CRM_Utils_System::redirect('?action=update&reset=1&id=' . $widget_id); } else { CRM_Utils_System::redirect('widget?reset=1'); } } catch (Exception $e) { CRM_Core_Session::setStatus(ts('Failed to create widget. ') . $e->getMessage(), '', 'error'); $transaction->rollback(); } parent::postProcess(); }
function postProcess() { $errorScope = CRM_Core_TemporaryErrorScope::useException(); if (isset($this->_id)) { try { $transaction = new CRM_Core_Transaction(); $sql = "UPDATE civicrm_wci_progress_bar SET name = %1,\n starting_amount = %2, goal_amount = %3 where id = %4"; CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST['progressbar_name'], 'String'), 2 => array($_REQUEST['starting_amount'], 'Float'), 3 => array($_REQUEST['goal_amount'], 'Float'), 4 => array($this->_id, 'Integer'))); /** Delete existiing formula fields and add fields fresh*/ CRM_Core_DAO::executeQuery('DELETE FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id=%1', array(1 => array($this->_id, 'Integer'))); $elem_added = 0; for ($i = 1; $elem_added < (int) $_REQUEST['contrib_count']; $i++) { if (!isset($_REQUEST['contribution_page_' . (string) $i])) { continue; } $page = 'contribution_page_' . (string) $i; $type = 'financial_type_' . (string) $i; $perc = 'percentage_' . (string) $i; $sdate = 'contribution_start_date_' . (string) $i; $edate = 'contribution_end_date_' . (string) $i; $sql = "INSERT INTO civicrm_wci_progress_bar_formula\n (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n VALUES (%1, %2, %3, %4, %5, %6)"; $start = NULL; $end = NULL; if (!empty($_REQUEST[$sdate])) { $start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd"); } if (!empty($_REQUEST[$edate])) { $end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd"); } CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST[$page], 'Integer'), 2 => array($_REQUEST[$type], 'Integer'), 3 => array($this->_id, 'Integer'), 4 => array($start, 'Date'), 5 => array($end, 'Date'), 6 => array($_REQUEST[$perc], 'Float'))); $elem_added++; } $transaction->commit(); CRM_Wci_BAO_WidgetCache::deleteWidgetCacheByProgressbar($this->_id); CRM_Core_Session::setStatus(ts('Progress bar created successfully'), '', 'success'); CRM_Utils_System::redirect('progress-bar?reset=1'); } catch (Exception $e) { CRM_Core_Session::setStatus(ts('Failed to create progress bar'), '', 'error'); $transaction->rollback(); } } else { $sql = "INSERT INTO civicrm_wci_progress_bar\n (name, starting_amount, goal_amount) VALUES (%1, %2, %3)"; try { $transaction = new CRM_Core_Transaction(); CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST['progressbar_name'], 'String'), 2 => array($_REQUEST['starting_amount'], 'Float'), 3 => array($_REQUEST['goal_amount'], 'Float'))); $progressbar_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); for ($i = 1; $i <= (int) $_REQUEST['contrib_count']; $i++) { $page = 'contribution_page_' . (string) $i; $type = 'financial_type_' . (string) $i; $perc = 'percentage_' . (string) $i; $sdate = 'contribution_start_date_' . (string) $i; $edate = 'contribution_end_date_' . (string) $i; $sql = "INSERT INTO civicrm_wci_progress_bar_formula\n (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage)\n VALUES (%1, %2, %3, %4, %5, %6)"; $start = NULL; $end = NULL; if (!empty($_REQUEST[$sdate])) { $start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd"); } if (!empty($_REQUEST[$edate])) { $end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd"); } CRM_Core_DAO::executeQuery($sql, array(1 => array($_REQUEST[$page], 'Integer'), 2 => array($_REQUEST[$type], 'Integer'), 3 => array($progressbar_id, 'Integer'), 4 => array($start, 'Date'), 5 => array($end, 'Date'), 6 => array($_REQUEST[$perc], 'Float'))); } $transaction->commit(); CRM_Utils_System::redirect('civicrm/wci/progress-bar?reset=1'); } catch (Exception $e) { CRM_Core_Session::setStatus(ts('Failed to create Progress bar. ') . $e->getMessage(), '', 'error'); $transaction->rollback(); } $elem = $this->getElement('contrib_count'); $elem->setValue('1'); } parent::postProcess(); }