fixed beta 1 bugs, 31062, 31063, 31101, 31067, 31065
[com.zyxware.civiwci.git] / extern / embed.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | 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 and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 */
34
35
36 /*
37 <script type="text/javascript" src="http://drupal.local/sites/all/modules/civicrm/extensions/civicrm-wci/extern/wciwidget.php?widgetId=1"></script>
38 */
39
40 require_once '../../../civicrm.config.php';
41 require_once '../wci-helper-functions.php';
42 require_once 'CRM/Core/Config.php';
43 require_once 'CRM/Contribute/BAO/Widget.php';
44 require_once 'CRM/Utils/Request.php';
45
46 $wciembed_js = '// Cleanup functions for the document ready method
47 if ( document.addEventListener ) {
48 DOMContentLoaded = function() {
49 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
50 onReady();
51 };
52 } else if ( document.attachEvent ) {
53 DOMContentLoaded = function() {
54 // Make sure body exists, at least, in case IE gets a little overzealous
55 if ( document.readyState === "complete" ) {
56 document.detachEvent( "onreadystatechange", DOMContentLoaded );
57 onReady();
58 }
59 };
60 }
61 if ( document.readyState === "complete" ) {
62 // Handle it asynchronously to allow scripts the opportunity to delay ready
63 setTimeout( onReady, 1 );
64 }
65
66 // Mozilla, Opera and webkit support this event
67 if ( document.addEventListener ) {
68 // Use the handy event callback
69 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
70 // A fallback to window.onload, that will always work
71 window.addEventListener( "load", onReady, false );
72 // If IE event model is used
73 } else if ( document.attachEvent ) {
74 // ensure firing before onload,
75 // maybe late but safe also for iframes
76 document.attachEvent("onreadystatechange", DOMContentLoaded);
77
78 // A fallback to window.onload, that will always work
79 window.attachEvent( "onload", onReady );
80 }
81
82 function onReady( ) {
83 document.getElementById("widgetwci").innerHTML = wciwidgetcode;
84 }';
85
86 $config = CRM_Core_Config::singleton();
87 $template = CRM_Core_Smarty::singleton();
88
89 $widgetId = CRM_Utils_Request::retrieve('widgetId', 'Positive', CRM_Core_DAO::$_nullObject);
90 if(empty($widgetId)) {
91 $embed = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject);
92 $widgetId = CRM_Wci_BAO_EmbedCode::getWidgetId($embed);
93
94 if(empty($widgetId)) {
95 $widgetId = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'default_wci_widget'));
96 }
97 }
98 $preview = CRM_Utils_Request::retrieve('preview', 'Positive', CRM_Core_DAO::$_nullObject);
99
100 if (isset($format)) {
101 $jsonvar .= $cpageId;
102 } else {
103 $widData = CRM_Wci_BAO_Widget::getWidgetData($widgetId);
104 $pbData = CRM_Wci_BAO_ProgressBar::getProgressbarData($widData["progress_bar_id"]);
105 $data = array_merge($widData, $pbData);
106
107 $template->assign('wciform', $data);
108 $template->assign('cpageId', $data['button_link_to']);
109 $template->assign('preview', $preview);
110
111 if ($data["override"] == '0') {
112 $template->template_dir[] = getWciWidgetTemplatePath();
113 $wcidata = $template->fetch('wciwidget.tpl');
114 } else {
115 $wcidata = $template->fetch('string:' . html_entity_decode($data['custom_template']));
116 }
117 $output = 'var wciwidgetcode = ' . json_encode($wcidata) . ';';
118
119 $output = $output . $wciembed_js;
120 echo $output;
121 }
122
123 CRM_Utils_System::civiExit();