PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_breezingforms/admin.breezingforms.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 907 lines | 845 code | 43 blank | 19 comment | 25 complexity | a717eef8b0ee850360f4bd4c69eb2f0c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * BreezingForms - A Joomla Forms Application
  4. * @version 1.8
  5. * @package BreezingForms
  6. * @copyright (C) 2008-2012 by Markus Bopp
  7. * @license Released under the terms of the GNU General Public License
  8. **/
  9. defined('_JEXEC') or die('Direct Access to this location is not allowed.');
  10. require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_breezingforms'.DS.'libraries'.DS.'crosstec'.DS.'classes'.DS.'BFJoomlaConfig.php');
  11. jimport('joomla.version');
  12. $version = new JVersion();
  13. function bf_getTableFields($tables, $typeOnly = true)
  14. {
  15. jimport('joomla.version');
  16. $version = new JVersion();
  17. if(version_compare($version->getShortVersion(), '3.0', '<')){
  18. return JFactory::getDBO()->getTableFields($tables);
  19. }
  20. $results = array();
  21. settype($tables, 'array');
  22. foreach ($tables as $table)
  23. {
  24. $results[$table] = JFactory::getDbo()->getTableColumns($table, $typeOnly);
  25. }
  26. return $results;
  27. }
  28. $option = JRequest::getCmd('option');
  29. $task = JRequest::getCmd('task');
  30. jimport('joomla.filesystem.file');
  31. jimport('joomla.filesystem.folder');
  32. if(version_compare($version->getShortVersion(), '1.6', '>=')){
  33. if ( !JFactory::getUser()->authorise('breezingforms.admin', 'com_breezingforms'))
  34. {
  35. return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
  36. }
  37. }
  38. // 1.7.5 to 1.8 cleanup
  39. if(JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_breezingforms'.DS.'install.secimage.php')){
  40. JFile::delete(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_breezingforms'.DS.'install.secimage.php');
  41. }
  42. if(JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_breezingforms'.DS.'uninstall.secimage.php')){
  43. JFile::delete(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_breezingforms'.DS.'uninstall.secimage.php');
  44. }
  45. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms')){
  46. JFolder::create(JPATH_SITE.DS.'media'.DS.'breezingforms');
  47. }
  48. if(!JFile::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'index.html')){
  49. JFile::copy(
  50. JPATH_SITE.DS.'components'.DS.'com_breezingforms'.DS.'index.html',
  51. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'index.html'
  52. );
  53. }
  54. #### MAIL TEMPLATES
  55. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'mailtpl')){
  56. JFolder::copy(
  57. JPATH_ADMINISTRATOR.DS.'components'.DS.'com_breezingforms'.DS.'mailtpl'.DS,
  58. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'mailtpl'.DS
  59. );
  60. }
  61. #### PDF TEMPLATES
  62. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'pdftpl')){
  63. JFolder::copy(
  64. JPATH_ADMINISTRATOR.DS.'components'.DS.'com_breezingforms'.DS.'pdftpl'.DS,
  65. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'pdftpl'.DS
  66. );
  67. }
  68. #### DOWNLOAD TEMPLATES
  69. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'downloadtpl')){
  70. JFolder::copy(
  71. JPATH_SITE.DS.'components'.DS.'com_breezingforms'.DS.'downloadtpl'.DS,
  72. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'downloadtpl'.DS
  73. );
  74. }
  75. #### UPLOADS
  76. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'uploads')){
  77. JFolder::create(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'uploads');
  78. JFile::copy(
  79. JPATH_SITE.DS.'components'.DS.'com_breezingforms'.DS.'uploads'.DS.'index.html',
  80. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'uploads'.DS.'index.html'
  81. );
  82. }
  83. #### THEMES
  84. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes')){
  85. JFolder::copy(
  86. JPATH_SITE.DS.'components'.DS.'com_breezingforms'.DS.'themes'.DS.'quickmode'.DS,
  87. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'quickmode'.DS
  88. );
  89. JFolder::move(
  90. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'quickmode'.DS,
  91. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS
  92. );
  93. }
  94. if(!JFolder::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'images')){
  95. JFolder::copy(
  96. JPATH_SITE.DS.'components'.DS.'com_breezingforms'.DS.'themes'.DS.'quickmode'.DS.'images'.DS,
  97. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'images'.DS
  98. );
  99. }
  100. if(!JFile::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'jq.mobile.min.css')){
  101. JFile::copy(
  102. JPATH_SITE.DS.'components'.DS.'com_breezingforms'.DS.'themes'.DS.'quickmode'.DS.'jq.mobile.min.css',
  103. JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'jq.mobile.min.css'
  104. );
  105. }
  106. #### DELETE SYSTEM THEMES FILES FROM MEDIA FOLDER (the ones in the original themes path are being used)
  107. if(JFile::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.css')){
  108. JFile::delete(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.css');
  109. }
  110. if(JFile::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.ie7.css')){
  111. JFile::delete(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.ie7.css');
  112. }
  113. if(JFile::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.ie6.css')){
  114. JFile::delete(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.ie6.css');
  115. }
  116. if(JFile::exists(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.ie.css')){
  117. JFile::delete(JPATH_SITE.DS.'media'.DS.'breezingforms'.DS.'themes'.DS.'system.ie.css');
  118. }
  119. /**
  120. *
  121. * SAME CHECKS FOR CAPTCHA AS IN FRONTEND, SINCE THEY DONT SHARE THE SAME SESSION
  122. *
  123. */
  124. if(JRequest::getBool('bfReCaptcha')){
  125. @ob_end_clean();
  126. require_once(JPATH_SITE.'/administrator/components/com_breezingforms/libraries/Zend/Json/Decoder.php');
  127. require_once(JPATH_SITE.'/administrator/components/com_breezingforms/libraries/Zend/Json/Encoder.php');
  128. $db = JFactory::getDBO();
  129. $db->setQuery( "Select * From #__facileforms_forms Where id = " . $db->Quote( JRequest::getInt('form',-1) ) );
  130. $list = $db->loadObjectList();
  131. if(count($list) == 0){
  132. exit;
  133. }
  134. $form = $list[0];
  135. $areas = Zend_Json::decode($form->template_areas);
  136. foreach($areas As $area){
  137. foreach($area['elements'] As $element){
  138. if($element['bfType'] == 'ReCaptcha'){
  139. if(!function_exists('recaptcha_check_answer')){
  140. require_once(JPATH_SITE . '/administrator/components/com_breezingforms/libraries/recaptcha/recaptchalib.php');
  141. }
  142. $publickey = $element['pubkey']; // you got this from the signup page
  143. $privatekey = $element['privkey'];
  144. $resp = recaptcha_check_answer ($privatekey,
  145. $_SERVER["REMOTE_ADDR"],
  146. isset( $_POST["recaptcha_challenge_field"] ) ? $_POST["recaptcha_challenge_field"] : '' ,
  147. isset($_POST["recaptcha_response_field"]) ? $_POST["recaptcha_response_field"] : '' );
  148. JFactory::getSession()->set('bfrecapsuccess',false);
  149. if ($resp->is_valid) {
  150. echo 'success';
  151. JFactory::getSession()->set('bfrecapsuccess',true);
  152. }
  153. else
  154. {
  155. die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
  156. "(reCAPTCHA said: " . $resp->error . ")");
  157. }
  158. exit;
  159. }
  160. }
  161. }
  162. exit;
  163. } else if(JRequest::getBool('checkCaptcha')){
  164. ob_end_clean();
  165. require_once(JPATH_SITE . '/components/com_breezingforms/images/captcha/securimage.php');
  166. $securimage = new Securimage();
  167. if(!$securimage->check(str_replace('?','',JRequest::getVar('value', '')))){
  168. echo 'capResult=>false';
  169. } else {
  170. echo 'capResult=>true';
  171. }
  172. exit;
  173. }
  174. $mainframe = JFactory::getApplication();
  175. $cache = JFactory::getCache('com_content');
  176. $cache->clean();
  177. // since joomla 1.6.2, load some behaviour to get the core.js files loaded
  178. if (version_compare($version->getShortVersion(), '1.6', '>=')) {
  179. JHtml::_('behavior.framework');
  180. }
  181. JHtml::_('behavior.tooltip');
  182. // purge ajax save
  183. $sourcePath = JPATH_SITE . DS . 'media' . DS . 'breezingforms' . DS . 'ajax_cache'.DS;
  184. if (@file_exists($sourcePath) && @is_readable($sourcePath) && @is_dir($sourcePath) && $handle = @opendir($sourcePath)) {
  185. while (false !== ($file = @readdir($handle))) {
  186. if($file!="." && $file!="..") {
  187. $parts = explode('_', $file);
  188. if(count($parts)==3 && $parts[0] == 'ajaxsave') {
  189. if (@JFile::exists($sourcePath.$file) && @is_readable($sourcePath.$file)) {
  190. $fileCreationTime = @filectime($sourcePath.$file);
  191. $fileAge = time() - $fileCreationTime;
  192. if($fileAge >= 3600) {
  193. @JFile::delete($sourcePath.$file);
  194. }
  195. }
  196. }
  197. }
  198. }
  199. @closedir($handle);
  200. }
  201. /**
  202. * DB UPGRADE BEGIN
  203. */
  204. $tables = bf_getTableFields( JFactory::getDBO()->getTableList() );
  205. if(isset($tables[JFactory::getDBO()->getPrefix().'facileforms_forms'])){
  206. /**
  207. * New as of 1.7.3
  208. */
  209. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_alt_mailfrom'] )){
  210. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_alt_mailfrom` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `alt_mailfrom` ");
  211. JFactory::getDBO()->query();
  212. }
  213. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_alt_fromname'] )){
  214. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_alt_fromname` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `alt_fromname` ");
  215. JFactory::getDBO()->query();
  216. }
  217. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_custom_mail_subject'] )){
  218. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_custom_mail_subject` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `custom_mail_subject` ");
  219. JFactory::getDBO()->query();
  220. }
  221. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_emailntf'] )){
  222. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_emailntf` tinyint( 1 ) NOT NULL DEFAULT 1 AFTER `emailntf` ");
  223. JFactory::getDBO()->query();
  224. }
  225. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_emaillog'] )){
  226. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_emaillog` tinyint( 1 ) NOT NULL DEFAULT 1 AFTER `emaillog` ");
  227. JFactory::getDBO()->query();
  228. }
  229. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_emailxml'] )){
  230. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_emailxml` tinyint( 1 ) NOT NULL DEFAULT 0 AFTER `emailxml` ");
  231. JFactory::getDBO()->query();
  232. }
  233. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['email_type'] )){
  234. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `email_type` tinyint( 1 ) NOT NULL DEFAULT 0 AFTER `mb_emailxml` ");
  235. JFactory::getDBO()->query();
  236. }
  237. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_email_type'] )){
  238. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_email_type` tinyint( 1 ) NOT NULL DEFAULT 0 AFTER `email_type` ");
  239. JFactory::getDBO()->query();
  240. }
  241. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['email_custom_template'] )){
  242. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `email_custom_template` TEXT AFTER `mb_email_type` ");
  243. JFactory::getDBO()->query();
  244. }
  245. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_email_custom_template'] )){
  246. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_email_custom_template` TEXT AFTER `email_custom_template` ");
  247. JFactory::getDBO()->query();
  248. }
  249. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['email_custom_html'] )){
  250. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `email_custom_html` tinyint( 1 ) NOT NULL DEFAULT 0 AFTER `mb_email_custom_template` ");
  251. JFactory::getDBO()->query();
  252. }
  253. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mb_email_custom_html'] )){
  254. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mb_email_custom_html` tinyint( 1 ) NOT NULL DEFAULT 0 AFTER `email_custom_html` ");
  255. JFactory::getDBO()->query();
  256. }
  257. /////
  258. // New as of 1.7.2
  259. /////
  260. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['alt_mailfrom'] )){
  261. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `alt_mailfrom` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `id` ");
  262. JFactory::getDBO()->query();
  263. }
  264. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['alt_fromname'] )){
  265. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `alt_fromname` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `alt_mailfrom` ");
  266. JFactory::getDBO()->query();
  267. }
  268. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_email_field'] )){
  269. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_email_field` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `alt_fromname` ");
  270. JFactory::getDBO()->query();
  271. }
  272. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_checkbox_field'] )){
  273. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_checkbox_field` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `mailchimp_email_field` ");
  274. JFactory::getDBO()->query();
  275. }
  276. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_api_key'] )){
  277. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_api_key` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `mailchimp_checkbox_field` ");
  278. JFactory::getDBO()->query();
  279. }
  280. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_list_id'] )){
  281. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_list_id` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `mailchimp_api_key` ");
  282. JFactory::getDBO()->query();
  283. }
  284. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_double_optin'] )){
  285. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_double_optin` TINYINT( 1 ) NOT NULL DEFAULT 1 AFTER `mailchimp_list_id` ");
  286. JFactory::getDBO()->query();
  287. }
  288. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_mergevars'] )){
  289. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_mergevars` TEXT AFTER `mailchimp_double_optin` ");
  290. JFactory::getDBO()->query();
  291. }
  292. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_text_html_mobile_field'] )){
  293. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_text_html_mobile_field` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `mailchimp_mergevars` ");
  294. JFactory::getDBO()->query();
  295. }
  296. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_send_errors'] )){
  297. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_send_errors` TINYINT( 1 ) NOT NULL DEFAULT 0 AFTER `mailchimp_text_html_mobile_field` ");
  298. JFactory::getDBO()->query();
  299. }
  300. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_update_existing'] )){
  301. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_update_existing` TINYINT( 1 ) NOT NULL DEFAULT 0 AFTER `mailchimp_send_errors` ");
  302. JFactory::getDBO()->query();
  303. }
  304. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_replace_interests'] )){
  305. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_replace_interests` TINYINT( 1 ) NOT NULL DEFAULT 0 AFTER `mailchimp_update_existing` ");
  306. JFactory::getDBO()->query();
  307. }
  308. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_send_welcome'] )){
  309. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_send_welcome` TINYINT( 1 ) NOT NULL DEFAULT 0 AFTER `mailchimp_replace_interests` ");
  310. JFactory::getDBO()->query();
  311. }
  312. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_default_type'] )){
  313. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_default_type` VARCHAR( 255 ) NOT NULL DEFAULT 'text' AFTER `mailchimp_send_welcome` ");
  314. JFactory::getDBO()->query();
  315. }
  316. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_delete_member'] )){
  317. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_delete_member` TINYINT( 1 ) NOT NULL DEFAULT 0 AFTER `mailchimp_default_type` ");
  318. JFactory::getDBO()->query();
  319. }
  320. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_send_goodbye'] )){
  321. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_send_goodbye` TINYINT( 1 ) NOT NULL DEFAULT 1 AFTER `mailchimp_delete_member` ");
  322. JFactory::getDBO()->query();
  323. }
  324. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_send_notify'] )){
  325. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_send_notify` TINYINT( 1 ) NOT NULL DEFAULT 1 AFTER `mailchimp_send_goodbye` ");
  326. JFactory::getDBO()->query();
  327. }
  328. if(!isset( $tables[JFactory::getDBO()->getPrefix().'facileforms_forms']['mailchimp_unsubscribe_field'] )){
  329. JFactory::getDBO()->setQuery("ALTER TABLE `#__facileforms_forms` ADD `mailchimp_unsubscribe_field` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `mailchimp_send_notify` ");
  330. JFactory::getDBO()->query();
  331. }
  332. }
  333. /**
  334. * DB UPGRADE END
  335. */
  336. require_once(JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFTabs.php');
  337. require_once(JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFText.php');
  338. require_once(JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFTableElements.php');
  339. require_once(JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/functions/helpers.php');
  340. require_once(JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/constants.php');
  341. jimport('joomla.version');
  342. $version = new JVersion();
  343. if(version_compare($version->getShortVersion(), '1.6', '>=')){
  344. JSubMenuHelper::addEntry(
  345. BFText::_('COM_BREEZINGFORMS_MANAGERECS'),
  346. 'index.php?option=com_breezingforms&act=managerecs', JRequest::getVar('act','') == 'managerecs' || JRequest::getVar('act','') == 'recordmanagement' || JRequest::getVar('act','') == '');
  347. JSubMenuHelper::addEntry(
  348. BFText::_('COM_BREEZINGFORMS_MANAGEFORMS'),
  349. 'index.php?option=com_breezingforms&act=manageforms', JRequest::getVar('act','') == 'manageforms' || JRequest::getVar('act','') == 'easymode' || JRequest::getVar('act','') == 'quickmode');
  350. JSubMenuHelper::addEntry(
  351. BFText::_('COM_BREEZINGFORMS_MANAGESCRIPTS'),
  352. 'index.php?option=com_breezingforms&act=managescripts', JRequest::getVar('act','') == 'managescripts');
  353. JSubMenuHelper::addEntry(
  354. BFText::_('COM_BREEZINGFORMS_MANAGEPIECES'),
  355. 'index.php?option=com_breezingforms&act=managepieces', JRequest::getVar('act','') == 'managepieces');
  356. JSubMenuHelper::addEntry(
  357. BFText::_('COM_BREEZINGFORMS_INTEGRATOR'),
  358. 'index.php?option=com_breezingforms&act=integrate', JRequest::getVar('act','') == 'integrate');
  359. JSubMenuHelper::addEntry(
  360. BFText::_('COM_BREEZINGFORMS_MANAGEMENUS'),
  361. 'index.php?option=com_breezingforms&act=managemenus', JRequest::getVar('act','') == 'managemenus');
  362. JSubMenuHelper::addEntry(
  363. BFText::_('COM_BREEZINGFORMS_CONFIG'),
  364. 'index.php?option=com_breezingforms&act=configuration', JRequest::getVar('act','') == 'configuration');
  365. }
  366. $_POST = bf_stripslashes_deep($_POST);
  367. $_GET = bf_stripslashes_deep($_GET);
  368. $_REQUEST = bf_stripslashes_deep($_REQUEST);
  369. $db = JFactory::getDBO();
  370. /*
  371. * Temporary section end
  372. */
  373. global $errors, $errmode;
  374. global $ff_mospath, $ff_admpath, $ff_compath, $ff_request;
  375. global $ff_mossite, $ff_admsite, $ff_admicon, $ff_comsite;
  376. global $ff_config, $ff_compatible, $ff_install;
  377. $my = JFactory::getUser();
  378. if (!isset($ff_compath)) { // joomla!
  379. jimport('joomla.version');
  380. $version = new JVersion();
  381. if(version_compare($version->getShortVersion(), '1.6', '<')){
  382. if ($my->usertype != 'Super Administrator' && $my->usertype != 'Administrator') {
  383. JFactory::getApplication()->redirect( 'index.php', BFText::_('COM_BREEZINGFORMS_NOT_AUTHORIZED') );
  384. } // if
  385. }
  386. // get paths
  387. $comppath = '/components/com_breezingforms';
  388. $ff_admpath = dirname(__FILE__);
  389. $ff_mospath = str_replace('\\','/',dirname(dirname(dirname($ff_admpath))));
  390. $ff_admpath = str_replace('\\','/',$ff_admpath);
  391. $ff_compath = $ff_mospath.$comppath;
  392. require_once($ff_admpath.'/toolbar.facileforms.php');
  393. } // if
  394. $errors = array();
  395. $errmode = 'die'; // die or log
  396. // compatibility check
  397. if (!$ff_compatible) {
  398. echo '<h1>'.BFText::_('COM_BREEZINGFORMS_INCOMPATIBLE').'</h1>';
  399. exit;
  400. } // if
  401. // load ff parameters
  402. $ff_request = array();
  403. reset($_REQUEST);
  404. while (list($prop, $val) = each($_REQUEST))
  405. if (is_scalar($val) && substr($prop,0,9)=='ff_param_')
  406. $ff_request[$prop] = $val;
  407. if ($ff_install) {
  408. $act = 'installation';
  409. $task = 'step2';
  410. } // if
  411. $ids = JRequest::getVar( 'ids', array());
  412. switch($act) {
  413. case 'installation':
  414. require_once($ff_admpath.'/admin/install.php');
  415. break;
  416. case 'configuration':
  417. require_once($ff_admpath.'/admin/config.php');
  418. break;
  419. case 'managemenus':
  420. require_once($ff_admpath.'/admin/menu.php');
  421. break;
  422. case 'manageforms':
  423. require_once($ff_admpath.'/admin/form.php');
  424. break;
  425. case 'editpage':
  426. require_once($ff_admpath.'/admin/element.php');
  427. break;
  428. case 'managescripts':
  429. require_once($ff_admpath.'/admin/script.php');
  430. break;
  431. case 'managepieces':
  432. require_once($ff_admpath.'/admin/piece.php');
  433. break;
  434. case 'run':
  435. require_once($ff_admpath.'/admin/run.php');
  436. break;
  437. case 'easymode':
  438. require_once($ff_admpath.'/admin/easymode.php');
  439. break;
  440. case 'quickmode':
  441. require_once($ff_admpath.'/admin/quickmode.php');
  442. break;
  443. case 'quickmode_editor':
  444. require_once($ff_admpath.'/admin/quickmode-editor.php');
  445. break;
  446. case 'integrate':
  447. require_once($ff_admpath.'/admin/integrator.php');
  448. break;
  449. case 'recordmanagement':
  450. require_once($ff_admpath.'/admin/recordmanagement.php');
  451. break;
  452. default:
  453. require_once($ff_admpath.'/admin/recordmanagement.php');
  454. break;
  455. } // switch
  456. // some general purpose functions for admin
  457. function isInputElement($type)
  458. {
  459. switch ($type) {
  460. case 'Static Text/HTML':
  461. case 'Rectangle':
  462. case 'Image':
  463. case 'Tooltip':
  464. case 'Query List':
  465. case 'Regular Button':
  466. case 'Graphic Button':
  467. case 'Icon':
  468. return false;
  469. default:
  470. break;
  471. } // switch
  472. return true;
  473. } // isInputElement
  474. function isVisibleElement($type)
  475. {
  476. switch ($type) {
  477. case 'Hidden Input':
  478. return false;
  479. default:
  480. break;
  481. } // switch
  482. return true;
  483. } // isVisibleElement
  484. function _ff_query($sql, $insert = 0)
  485. {
  486. global $database, $errors;
  487. $database = JFactory::getDBO();
  488. $id = null;
  489. $database->setQuery($sql);
  490. $database->query();
  491. if ($database->getErrorNum()) {
  492. if (isset($errmode) && $errmode=='log')
  493. $errors[] = $database->getErrorMsg();
  494. else
  495. die($database->stderr());
  496. } // if
  497. if ($insert) $id = $database->insertid();
  498. return $id;
  499. } // _ff_query
  500. function _ff_select($sql)
  501. {
  502. global $database, $errors;
  503. $database = JFactory::getDBO();
  504. $database->setQuery($sql);
  505. $rows = $database->loadObjectList();
  506. if ($database->getErrorNum()) {
  507. if (isset($errmode) && $errmode=='log')
  508. $errors[] = $database->getErrorMsg();
  509. else
  510. die($database->stderr());
  511. } // if
  512. return $rows;
  513. } // _ff_select
  514. function _ff_selectValue($sql)
  515. {
  516. global $database, $errors;
  517. $database = JFactory::getDBO();
  518. $database->setQuery($sql);
  519. $value = $database->loadResult();
  520. if ($database->getErrorNum()) {
  521. die($database->stderr());
  522. } // if
  523. return $value;
  524. } // _ff_selectValue
  525. function protectedComponentIds()
  526. {
  527. jimport('joomla.version');
  528. $version = new JVersion();
  529. if(version_compare($version->getShortVersion(), '1.6', '>=')){
  530. $rows = _ff_select(
  531. "select id, parent_id As parent from #__menu ".
  532. "where ".
  533. " link in (".
  534. "'index.php?option=com_breezingforms&act=managerecs',".
  535. "'index.php?option=com_breezingforms&act=managemenus',".
  536. "'index.php?option=com_breezingforms&act=manageforms',".
  537. "'index.php?option=com_breezingforms&act=managescripts',".
  538. "'index.php?option=com_breezingforms&act=managepieces',".
  539. "'index.php?option=com_breezingforms&act=share',".
  540. "'index.php?option=com_breezingforms&act=integrate',".
  541. "'index.php?option=com_breezingforms&act=configuration'".
  542. ") ".
  543. "order by id"
  544. );
  545. }else{
  546. $rows = _ff_select(
  547. "select id, parent from #__components ".
  548. "where `option`='com_breezingforms' ".
  549. "and admin_menu_link in (".
  550. "'option=com_breezingforms&act=managerecs',".
  551. "'option=com_breezingforms&act=managemenus',".
  552. "'option=com_breezingforms&act=manageforms',".
  553. "'option=com_breezingforms&act=managescripts',".
  554. "'option=com_breezingforms&act=managepieces',".
  555. "'option=com_breezingforms&act=share',".
  556. "'option=com_breezingforms&act=integrate',".
  557. "'option=com_breezingforms&act=configuration'".
  558. ") ".
  559. "order by id"
  560. );
  561. }
  562. $parent = 0;
  563. $ids = array();
  564. if (count($rows))
  565. foreach ($rows as $row) {
  566. if ($parent == 0) {
  567. $parent = 1;
  568. if(isset($row->parent)){
  569. $ids[] = $row->parent;
  570. }
  571. } // if
  572. $ids[] = $row->id;
  573. } // foreach
  574. return implode($ids, ',');
  575. } // protectedComponentIds
  576. function addComponentMenu($row, $parent, $copy = false)
  577. {
  578. $db = JFactory::getDBO();
  579. $admin_menu_link = '';
  580. if ($row->name!='') {
  581. $admin_menu_link =
  582. 'option=com_breezingforms'.
  583. '&act=run'.
  584. '&ff_name='.$row->name;
  585. if ($row->page!=1) $admin_menu_link .= '&ff_page='.$row->page;
  586. if ($row->frame==1) $admin_menu_link .= '&ff_frame=1';
  587. if ($row->border==1) $admin_menu_link .= '&ff_border=1';
  588. if ($row->params!='') $admin_menu_link .= $row->params;
  589. } // if
  590. if ($parent==0) $ordering = 0; else $ordering = $row->ordering;
  591. jimport('joomla.version');
  592. $version = new JVersion();
  593. if(version_compare($version->getShortVersion(), '3.0', '<') && version_compare($version->getShortVersion(), '1.6', '>=')){
  594. $parent = $parent == 0 ? 1 : $parent;
  595. $db->setQuery("Select component_id From #__menu Where link = 'index.php?option=com_breezingforms' And parent_id = 1");
  596. $result = $db->loadResult();
  597. if($result){
  598. return _ff_query(
  599. "insert into #__menu (".
  600. "`title`, alias, menutype, parent_id, ".
  601. "link,".
  602. "ordering, level, component_id, client_id, img, lft, rgt".
  603. ") ".
  604. "values (".$db->Quote( ($copy ? 'Copy of ' : '') . $row->title . ($copy ? ' ('.md5(session_id().microtime().mt_rand(0, mt_getrandmax())).')' : '')).", ".$db->Quote( ($copy ? 'Copy of ' : '') . $row->title . ($copy ? ' ('.md5(session_id().microtime().mt_rand(0, mt_getrandmax())).')' : '')).", 'menu', $parent, ".
  605. "'index.php?$admin_menu_link',".
  606. "'$ordering', 1, ".intval($result).", 1, 'components/com_breezingforms/images/$row->img',( Select mlftrgt From (Select max(mlft.rgt)+1 As mlftrgt From #__menu As mlft) As tbone ),( Select mrgtrgt From (Select max(mrgt.rgt)+2 As mrgtrgt From #__menu As mrgt) As filet )".
  607. ")",
  608. true
  609. );
  610. }else{
  611. die("BreezingForms main menu item not found!");
  612. }
  613. } else if(version_compare($version->getShortVersion(), '3.0', '>=')){
  614. $parent = $parent == 0 ? 1 : $parent;
  615. $db->setQuery("Select component_id From #__menu Where link = 'index.php?option=com_breezingforms' And parent_id = 1");
  616. $result = $db->loadResult();
  617. if($result){
  618. return _ff_query(
  619. "insert into #__menu (".
  620. "`title`, alias, menutype, parent_id, ".
  621. "link,".
  622. "level, component_id, client_id, img, lft, rgt".
  623. ") ".
  624. "values (".$db->Quote( ($copy ? 'Copy of ' : '') . $row->title . ($copy ? ' ('.md5(session_id().microtime().mt_rand(0, mt_getrandmax())).')' : '')).", ".$db->Quote( ($copy ? 'Copy of ' : '') . $row->title . ($copy ? ' ('.md5(session_id().microtime().mt_rand(0, mt_getrandmax())).')' : '')).", 'menu', $parent, ".
  625. "'index.php?$admin_menu_link',".
  626. "1, ".intval($result).", 1, 'components/com_breezingforms/images/$row->img',( Select mlftrgt From (Select max(mlft.rgt)+1 As mlftrgt From #__menu As mlft) As tbone ),( Select mrgtrgt From (Select max(mrgt.rgt)+2 As mrgtrgt From #__menu As mrgt) As filet )".
  627. ")",
  628. true
  629. );
  630. }else{
  631. die("BreezingForms main menu item not found!");
  632. }
  633. }
  634. // if older JVersion
  635. return _ff_query(
  636. "insert into #__components (".
  637. "id, name, link, menuid, parent, ".
  638. "admin_menu_link, admin_menu_alt, `option`, ".
  639. "ordering, admin_menu_img, iscore, params".
  640. ") ".
  641. "values (".
  642. "'', ".$db->Quote($row->title).", '', 0, $parent, ".
  643. "'$admin_menu_link', ".$db->Quote($row->title).", 'com_breezingforms', ".
  644. "'$ordering', '$row->img', 1, ''".
  645. ")",
  646. true
  647. );
  648. } // addComponentMenu
  649. function updateComponentMenus($copy = false)
  650. {
  651. // remove unprotected menu items
  652. $protids = protectedComponentIds();
  653. if(trim($protids)!=''){
  654. jimport('joomla.version');
  655. $version = new JVersion();
  656. if(version_compare($version->getShortVersion(), '1.6', '>=')){
  657. _ff_query(
  658. "delete from #__menu ".
  659. "where `link` Like 'index.php?option=com_breezingforms%' ".
  660. "and id not in ($protids) And `menutype` <> 'mainmenu'"
  661. );
  662. }else{
  663. _ff_query(
  664. "delete from #__components ".
  665. "where `option`='com_breezingforms' ".
  666. "and id not in ($protids)"
  667. );
  668. }
  669. }
  670. // add published menu items
  671. $rows = _ff_select(
  672. "select ".
  673. "m.id as id, ".
  674. "m.parent as parent, ".
  675. "m.ordering as ordering, ".
  676. "m.title as title, ".
  677. "m.img as img, ".
  678. "m.name as name, ".
  679. "m.page as page, ".
  680. "m.frame as frame, ".
  681. "m.border as border, ".
  682. "m.params as params, ".
  683. "m.published as published ".
  684. "from #__facileforms_compmenus as m ".
  685. "left join #__facileforms_compmenus as p on m.parent=p.id ".
  686. "where m.published=1 ".
  687. "and (m.parent=0 or p.published=1) ".
  688. "order by ".
  689. "if(m.parent,p.ordering,m.ordering), ".
  690. "if(m.parent,m.ordering,-1)"
  691. );
  692. $parent = 0;
  693. if (count($rows)) foreach ($rows as $row) {
  694. jimport('joomla.version');
  695. $version = new JVersion();
  696. if(version_compare($version->getShortVersion(), '1.6', '>=')){
  697. JFactory::getDBO()->setQuery("Select id From #__menu Where `alias` = " . JFactory::getDBO()->Quote($row->title));
  698. if(JFactory::getDBO()->loadResult()){
  699. return BFText::_('COM_BREEZINGFORMS_MENU_ITEM_EXISTS');
  700. }
  701. if ($row->parent==0 || $row->parent==1){
  702. $parent = addComponentMenu($row, 1, $copy);
  703. }else{
  704. addComponentMenu($row, $parent, $copy);
  705. }
  706. }else{
  707. if ($row->parent==0){
  708. $parent = addComponentMenu($row, 0);
  709. }else{
  710. addComponentMenu($row, $parent);
  711. }
  712. }
  713. } // foreach
  714. return '';
  715. } // updateComponentMenus
  716. function dropPackage($id)
  717. {
  718. // drop package settings
  719. _ff_query("delete from #__facileforms_packages where id = ".JFactory::getDBO()->Quote($id)."");
  720. // drop backend menus
  721. $rows = _ff_select("select id from #__facileforms_compmenus where package = ".JFactory::getDBO()->Quote($id)."");
  722. if (count($rows)) foreach ($rows as $row)
  723. _ff_query("delete from #__facileforms_compmenus where id=$row->id or parent=$row->id");
  724. updateComponentMenus();
  725. // drop forms
  726. $rows = _ff_select("select id from #__facileforms_forms where package = ".JFactory::getDBO()->Quote($id)."");
  727. if (count($rows)) foreach ($rows as $row) {
  728. _ff_query("delete from #__facileforms_elements where form = $row->id");
  729. _ff_query("delete from #__facileforms_forms where id = $row->id");
  730. } // if
  731. // drop scripts
  732. _ff_query("delete from #__facileforms_scripts where package = ".JFactory::getDBO()->Quote($id)."");
  733. // drop pieces
  734. _ff_query("delete from #__facileforms_pieces where package = ".JFactory::getDBO()->Quote($id)."");
  735. } // dropPackage
  736. function savePackage($id, $name, $title, $version, $created, $author, $email, $url, $description, $copyright)
  737. {
  738. $db = JFactory::getDBO();
  739. $cnt = _ff_selectValue("select count(*) from #__facileforms_packages where id=".JFactory::getDBO()->Quote($id)."");
  740. if (!$cnt) {
  741. _ff_query(
  742. "insert into #__facileforms_packages ".
  743. "(id, name, title, version, created, author, ".
  744. "email, url, description, copyright) ".
  745. "values (".$db->Quote($id).", ".$db->Quote($name).", ".$db->Quote($title).", ".$db->Quote($version).", ".$db->Quote($created).", ".$db->Quote($author).",
  746. ".$db->Quote($email).", ".$db->Quote($url).", ".$db->Quote($description).", ".$db->Quote($copyright).")"
  747. );
  748. } else {
  749. _ff_query(
  750. "update #__facileforms_packages ".
  751. "set name=".$db->Quote($name).", title=".$db->Quote($title).", version=".$db->Quote($version).", created=".$db->Quote($created).", author=".$db->Quote($author).", ".
  752. "email=".$db->Quote($email).", url=".$db->Quote($url).", description=".$db->Quote($description).", copyright=".$db->Quote($copyright). "
  753. where id = ".$db->Quote($id)
  754. );
  755. } // if
  756. } // savePackage
  757. function relinkScripts(&$oldscripts)
  758. {
  759. if (count($oldscripts))
  760. foreach ($oldscripts as $row) {
  761. $newid = _ff_selectValue("select max(id) from #__facileforms_scripts where name = ".JFactory::getDBO()->Quote($row->name)."");
  762. if ($newid) {
  763. _ff_query("update #__facileforms_forms set script1id=$newid where script1id=$row->id");
  764. _ff_query("update #__facileforms_forms set script2id=$newid where script2id=$row->id");
  765. _ff_query("update #__facileforms_elements set script1id=$newid where script1id=$row->id");
  766. _ff_query("update #__facileforms_elements set script2id=$newid where script2id=$row->id");
  767. _ff_query("update #__facileforms_elements set script3id=$newid where script3id=$row->id");
  768. } // if
  769. } // foreach
  770. } // relinkScripts
  771. function relinkPieces(&$oldpieces)
  772. {
  773. if (count($oldpieces))
  774. foreach ($oldpieces as $row) {
  775. $newid = _ff_selectValue("select max(id) from #__facileforms_pieces where name = ".JFactory::getDBO()->Quote($row->name)."");
  776. if ($newid) {
  777. _ff_query("update #__facileforms_forms set piece1id=$newid where piece1id=$row->id");
  778. _ff_query("update #__facileforms_forms set piece2id=$newid where piece2id=$row->id");
  779. _ff_query("update #__facileforms_forms set piece3id=$newid where piece3id=$row->id");
  780. _ff_query("update #__facileforms_forms set piece4id=$newid where piece4id=$row->id");
  781. } // if
  782. } // foreach
  783. } // relinkPieces
  784. ?>