PageRenderTime 71ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/site/administrator/components/com_chronocontact/admin.chronocontact.php

https://bitbucket.org/manchas/jrobotz
PHP | 2787 lines | 2643 code | 49 blank | 95 comment | 144 complexity | 52ca23979c2c0b4ebe3cec059832eadb MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /*
  3. /**
  4. * CHRONOFORMS version 3.0
  5. * Copyright (c) 2008 Chrono_Man, ChronoEngine.com. All rights reserved.
  6. * Author: Chrono_Man (ChronoEngine.com)
  7. * See readme.html.
  8. * @license GNU/GPL
  9. * Visit http://www.ChronoEngine.com for regular update and information.
  10. **/
  11. /* ensure that this file is not called from another file */
  12. defined('_JEXEC') or die('Restricted access');
  13. //global $mosConfig_lang, $mosConfig_absolute_path, $chronocontact_params;
  14. // Loading of the database class and the HTML class
  15. require_once( JApplicationHelper::getPath( 'admin_html' ) );
  16. require_once( JApplicationHelper::getPath( 'class' ) );
  17. $id = JRequest::getVar( 'id', '', 'get', 'int', 0 );
  18. //$task = JRequest::getVar( 'task', '', 'post', 'string', '' );
  19. $cid = JRequest::getVar( 'cid', array(), 'post', 'array');
  20. if (!is_array( $cid )) {
  21. $cid = array(0);
  22. }
  23. $cid_del = JRequest::getVar( 'cid_del', array(), 'post', 'array');
  24. if (!is_array( $cid_del )) {
  25. $cid_del = array(0);
  26. }
  27. ?>
  28. <?php echo JHTML::_('behavior.tooltip'); ?>
  29. <?php
  30. // case differentiation
  31. switch ($task) {
  32. case "ajax":
  33. ajaxfields();
  34. break;
  35. case "adminview":
  36. showadminformChronoContact( '', $cid[0], $option );
  37. break;
  38. case "submitadminform":
  39. submitadminformChronoContact( $option );
  40. break;
  41. case "editdata":
  42. showadminformChronoContact( $cid[0], '', $option );
  43. break;
  44. case "transform":
  45. transformChronoContact( $cid[0], $option );
  46. break;
  47. case "savetransform":
  48. savetransformChronoContact( $option );
  49. break;
  50. case "previewajax":
  51. previewajaxChronoContact( $option );
  52. break;
  53. case 'doupgrade':
  54. doupgrade($option);
  55. break;
  56. case 'validatelicense':
  57. validatelicense($option);
  58. break;
  59. case 'validatelicenseframe':
  60. validatelicenseframe($option);
  61. break;
  62. case 'validatelicensedata':
  63. validatelicensedata();
  64. break;
  65. /////////////////////
  66. case "publish":
  67. publishChronoContact( $cid, 1, $option );
  68. break;
  69. case "unpublish":
  70. publishChronoContact( $cid, 0, $option );
  71. break;
  72. case "add":
  73. editChronoContact( 0, $option );
  74. break;
  75. case "edit":
  76. editChronoContact( $cid[0], $option );
  77. break;
  78. case "applychanges":
  79. saveChronoContact( $option, $task );
  80. //editChronoContact( $_POST['id'], $option );
  81. break;
  82. case "remove":
  83. removeChronoContact( $cid, $option );
  84. break;
  85. case "save":
  86. saveChronoContact( $option, $task );
  87. break;
  88. case "copy":
  89. copyChronoContact( $cid[0], $option );
  90. break;
  91. case "cancel":
  92. cancelChronoContact( $option );
  93. break;
  94. case "addmenuitem":
  95. addmenuitem( $option );
  96. break;
  97. ////////
  98. case "cancelview":
  99. showdataChronoContact( 0, $option );
  100. break;
  101. case "show":
  102. $showid = (count($cid) == 0) ? 0 : $cid[0];
  103. showdataChronoContact( $showid, $option );
  104. break;
  105. case "viewdata":
  106. viewdataChronoContact( $cid[0], $option );
  107. break;
  108. case "createtable":
  109. maketableChronoContact( $cid[0], $option );
  110. break;
  111. case "edittable":
  112. maketableChronoContact( 0, $option );
  113. break;
  114. case "tablemanager":
  115. tablemanagerChronoContact( $option );
  116. break;
  117. case "updatetablelist":
  118. updatetablelistChronoContact( $option );
  119. break;
  120. case "deletetable":
  121. deletetableChronoContact( $cid[0], $option);
  122. break;
  123. case "finalizetable":
  124. finalizetableChronoContact( $option );
  125. break;
  126. case "deleterecord":
  127. deleterecordChronoContact( $cid, $option );
  128. break;
  129. ////// backup
  130. case "backup":
  131. case "backupall":
  132. backupChronoContact( $cid[0], $option, $task );
  133. break;
  134. case "restore1":
  135. restore1ChronoContact( 0, $option );
  136. break;
  137. case "restore2":
  138. restore2ChronoContact( 0, $option );
  139. break;
  140. case "backexcel":
  141. BackupExcel( $id, $option );
  142. break;
  143. case "backcsv":
  144. BackupCSV( $id, $option );
  145. break;
  146. ////// config
  147. case 'config':
  148. showConfig( $option );
  149. break;
  150. case 'saveconfig':
  151. saveSettings( $option );
  152. break;
  153. case 'cancelconfig':
  154. cancelSettings( $option );
  155. break;
  156. case 'save_conf':
  157. save_conf( $option );
  158. break;
  159. ////// wizard
  160. case 'form_wizard':
  161. form_wizard( '', $option );
  162. break;
  163. case 'wizardedit':
  164. form_wizard( $cid[0], $option );
  165. break;
  166. case 'wizard_elements':
  167. wizard_elements( $option );
  168. break;
  169. case 'save_form_wizard':
  170. save_form_wizard( $option );
  171. break;
  172. case 'editelement':
  173. editElement( $cid[0], $option );
  174. break;
  175. case 'newelement':
  176. editElement( 0, $option );
  177. break;
  178. case 'saveelement':
  179. case 'applyelement':
  180. saveElement( $task, $option );
  181. break;
  182. case 'cancelelement':
  183. cancelElement( $option );
  184. break;
  185. case 'deleteelement':
  186. deleteElement( $cid, $option );
  187. break;
  188. ///// menu tools
  189. case 'menu_creator':
  190. menu_creator( $option );
  191. break;
  192. case 'menu_remover':
  193. menu_remover( $option );
  194. break;
  195. case 'menu_save':
  196. menu_save( $option );
  197. break;
  198. case 'menu_delete':
  199. menu_delete( $cid, $option );
  200. break;
  201. ///////////////
  202. default:
  203. global $mainframe;
  204. $database =& JFactory::getDBO();
  205. $switch = 1;
  206. if(strpos("x".$task,"plugin_")){
  207. $directory = JPATH_SITE.'/components/com_chronocontact/plugins/';
  208. $results = array();
  209. $handler = opendir($directory);
  210. while ($file = readdir($handler)) {
  211. if ( $file != '.' && $file != '..' && substr($file, -4) == '.php' && substr($file, 0, 3) == 'cf_')
  212. $results[] = str_replace(".php","", $file);
  213. }
  214. closedir($handler);
  215. foreach($results as $result){
  216. if($task == 'plugin_'.$result){
  217. require_once(JPATH_SITE."/components/com_chronocontact/plugins/".$result.".php");
  218. ${$result} = new $result();
  219. $switch = 0;
  220. $database->setQuery( "SELECT id FROM #__chrono_contact_plugins WHERE form_id='".$cid[0]."' AND name='".$result."'" );
  221. $id = $database->loadResult();
  222. $row =& JTable::getInstance('chronocontactplugins', 'Table');
  223. $row->load( $id );
  224. ${$result}->show_conf($row, $id, $cid[0], $option);
  225. break;
  226. }
  227. }
  228. }
  229. //echo 'xxx'.$cf_joomla_registration->result_TITLE;
  230. if($switch == 1){
  231. showChronoContact( $option );
  232. }
  233. break;
  234. }
  235. function save_conf( $option ){
  236. $plugin = JRequest::getVar('name');
  237. require_once(JPATH_SITE."/components/com_chronocontact/plugins/".$plugin.".php");
  238. ${$plugin} = new $plugin();
  239. ${$plugin}->save_conf($option);
  240. }
  241. function ajaxfields(){
  242. global $mainframe;
  243. $database =& JFactory::getDBO();
  244. $plugin = JRequest::getVar('plugin');
  245. $method = JRequest::getVar('method');
  246. require_once(JPATH_SITE."/components".DS."com_chronocontact".DS."plugins".DS.$plugin.".php");
  247. ${$plugin} = new $plugin();
  248. ${$plugin}->{$method}();
  249. }
  250. function doupgrade($option){
  251. global $mainframe;
  252. $database =& JFactory::getDBO();
  253. $sql = "ALTER TABLE #__chrono_contact ADD `extravalrules` LONGTEXT NOT NULL AFTER `titlesall`";
  254. $database->setQuery($sql);
  255. if (!$database->query()) {
  256. echo $database->getErrorMsg();
  257. }
  258. $sql = "ALTER TABLE #__chrono_contact ADD `stylecode` LONGTEXT NOT NULL AFTER `scriptcode`";
  259. $database->setQuery($sql);
  260. if (!$database->query()) {
  261. echo $database->getErrorMsg();
  262. }
  263. $sql = "ALTER TABLE #__chrono_contact ADD `chronocode` LONGTEXT NOT NULL AFTER `autogenerated`";
  264. $database->setQuery($sql);
  265. if (!$database->query()) {
  266. echo $database->getErrorMsg();
  267. }
  268. $sql = "ALTER TABLE #__chrono_contact ADD `theme` TEXT NOT NULL AFTER `chronocode`";
  269. $database->setQuery($sql);
  270. if (!$database->query()) {
  271. echo $database->getErrorMsg();
  272. }
  273. $sql = "ALTER TABLE #__chrono_contact_emails
  274. ADD COLUMN `replytoname` TEXT AFTER `dfromemail`,
  275. ADD COLUMN `dreplytoname` TEXT AFTER `replytoname`,
  276. ADD COLUMN `replytoemail` TEXT AFTER `dreplytoname`,
  277. ADD COLUMN `dreplytoemail` TEXT AFTER `replytoemail`;";
  278. $database->setQuery($sql);
  279. if (!$database->query()) {
  280. echo $database->getErrorMsg();
  281. }
  282. $sql = "ALTER TABLE #__chrono_contact_elements
  283. ADD COLUMN `title` VARCHAR(255) AFTER `id`,
  284. ADD COLUMN `params` LONGTEXT AFTER `code`;";
  285. $database->setQuery($sql);
  286. if (!$database->query()) {
  287. echo $database->getErrorMsg();
  288. }
  289. // Load Demo form
  290. $option = 'com_chronocontact';
  291. $filename = 'basicDemo.cfbak';
  292. $path = JPATH_SITE.DS.'components'.DS.'com_chronocontact'.DS.'uploads';
  293. $data = file_get_contents( $path.DS.$filename );
  294. $data = str_replace( '&amp;', '&', $data );
  295. $values = '(';
  296. $values2 = '(';
  297. preg_match_all('/\<++(.*?)\<endendend>/s', $data, $matches);
  298. $i = 0;
  299. foreach ( $matches[0] as $match ) {
  300. if($i != 0){
  301. $values .= ',';
  302. $values2 .= ',';
  303. }
  304. preg_match_all('/\<++(.*?)\++>/s', $match, $match2es);
  305. $fieldvalue = str_replace($match2es[0][0],'',$match);
  306. $match2es[0][0] = str_replace('<++-++-++','',$match2es[0][0]);
  307. $match2es[0][0] = str_replace('++-++-++>','',$match2es[0][0]);
  308. $values .= $match2es[0][0];
  309. if($i == 0){
  310. $values2 .= "''";
  311. }else{
  312. $match = str_replace('<++-++-++'.$match2es[0][0].'++-++-++>','',$match);
  313. $match = str_replace('<endendend>','',$match);
  314. $match = trim($match," \t.");
  315. $values2 .= "'".addslashes($match)."'";
  316. }
  317. $i++;
  318. }
  319. $values .= ')';
  320. $values2 .= ')';
  321. $database->setQuery( "INSERT INTO #__chrono_contact ".$values." VALUES ".$values2 );
  322. if (!$database->query()) {
  323. JError::raiseWarning(100, "Restoring the whole form failed Failed, error : ".$database->getErrorMsg());
  324. //$mainframe->redirect( "index2.php?option=$option" );
  325. }else{
  326. //$mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
  327. }
  328. $lastformid = $database->insertid();
  329. // Restore Emails
  330. $values = '(`';
  331. $values2 = '(';
  332. $emails_data = array();
  333. $emails_count = explode('<cf_email_separator>', $data);
  334. $fields_count_1 = explode('{cfbak_start_emails}', $emails_count[0]);
  335. $fields_count_2 = explode('<endendend2>', $fields_count_1[1]);
  336. preg_match_all('/\<2++(.*?)\<endendend2>/s', $data, $matches);
  337. $i = 0;
  338. $i_v = 0;
  339. $counter = 0;
  340. foreach ( $matches[0] as $match ) {
  341. preg_match_all('/\<2++(.*?)\++>/s', $match, $match2es);
  342. $fieldvalue = str_replace($match2es[0][0],'',$match);
  343. $match2es[0][0] = str_replace('<2++-++-++','',$match2es[0][0]);
  344. $match2es[0][0] = str_replace('++-++-++>','',$match2es[0][0]);
  345. if($i_v < (count($fields_count_2) - 1)){
  346. if($i_v != 0){$values .= '`,`';}
  347. $values .= $match2es[0][0];
  348. }
  349. if($i != 0){$values2 .= ',';}
  350. if($i == 0){
  351. $values2 .= "''";
  352. }else if($i == 1){
  353. $values2 .= "'".$lastformid."'";
  354. }else{
  355. $match = str_replace('<2++-++-++'.$match2es[0][0].'++-++-++>','',$match);
  356. $match = str_replace('<endendend2>','',$match);
  357. $match = trim($match," \t.");
  358. $values2 .= "'".addslashes($match)."'";
  359. }
  360. $counter++;
  361. $i++;
  362. $i_v++;
  363. if($counter == (count($fields_count_2) - 1)){
  364. $values2 .= ')';
  365. $emails_data[] = $values2;
  366. $values2 = '(';
  367. $counter = 0;
  368. $i = 0;
  369. }
  370. }
  371. $values .= '`)';
  372. foreach($emails_data as $email_data){
  373. $database->setQuery( "INSERT INTO #__chrono_contact_emails ".$values." VALUES ".$email_data );
  374. if (!$database->query()) {
  375. JError::raiseWarning(100, "Restoring Emails Setup Failed, error : ".$database->getErrorMsg());
  376. //$mainframe->redirect( "index2.php?option=$option" );
  377. }else{
  378. //$mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
  379. }
  380. }
  381. //$mainframe->redirect( 'index2.php?option='.$option , "Demo form loaded successfully");
  382. $mainframe->redirect( "index2.php?option=$option", 'Upgrade went successfully' );
  383. }
  384. function validatelicense($option){
  385. HTML_ChronoContact::validatelicensepage( $option );
  386. }
  387. function validatelicenseframe($option){
  388. //HTML_ChronoContact::validatelicenseframe( $option );
  389. }
  390. function validatelicensedata(){
  391. global $mainframe;
  392. preg_match('/http(s)*:\/\/(.*?)\//i', $mainframe->getSiteURL(), $matches);
  393. $database =& JFactory::getDBO();
  394. $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
  395. $database->setQuery( $query );
  396. $result = $database->loadObject();
  397. //$configs = JComponentHelper::getParams('com_chronocontact');
  398. $configs = new JParameter($result->params);
  399. $postfields = array();
  400. $postfields['license_key'] = $configs->get('licensecode', '');
  401. $postfields['domain_name'] = $matches[2];
  402. $postfields['pid'] = $_POST['pid'];
  403. $validstatus = false;
  404. if(function_exists('fsockopen')){
  405. $validstatus = validationconnect('http', 'www.chronoengine.com', $port='80', $path='/index2.php?option=com_chronocontact&task=extra&chronoformname=validateLicense', $postfields);
  406. }
  407. if((!$validstatus)||($validstatus == 'error')||!function_exists('fsockopen')){
  408. if (!function_exists('curl_init')){
  409. $validstatus = false;
  410. }else{
  411. $fields = '';
  412. $ch = curl_init();
  413. //$postfields = array();
  414. foreach( $postfields as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";
  415. curl_setopt($ch, CURLOPT_URL, 'http://www.chronoengine.com/index2.php?option=com_chronocontact&task=extra&chronoformname=validateLicense');
  416. curl_setopt($ch, CURLOPT_HEADER, 0);
  417. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  418. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  419. curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " ));
  420. if($configs->get('curlproxy', '')){
  421. curl_setopt($ch, CURLOPT_PROXY, $configs->get('curlproxy'));
  422. }
  423. $output = curl_exec($ch);
  424. curl_close($ch);
  425. $validstatus = $output;
  426. }
  427. }
  428. //return $validstatus;
  429. if($validstatus == 'valid'){
  430. if($configs->get('licensecode', '')){
  431. //if(!$configs->get('licensevalid', '')){
  432. $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
  433. $database->setQuery( $query );
  434. $result = $database->loadObject();
  435. $newline = "\n";
  436. if($result){
  437. $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=1';
  438. $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
  439. if (!$database->query()) {
  440. JError::raiseWarning(100, $database->getErrorMsg());
  441. $mainframe->redirect( "index2.php?option=com_chronocontact" );
  442. }
  443. }
  444. //}
  445. }
  446. $mainframe->redirect( "index2.php?option=com_chronocontact", 'Your Install was validated successfully' );
  447. }else if($validstatus == 'invalid'){
  448. $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
  449. $database->setQuery( $query );
  450. $result = $database->loadObject();
  451. $newline = "\n";
  452. if($result){
  453. $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=0';
  454. $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
  455. if (!$database->query()) {
  456. JError::raiseWarning(100, $database->getErrorMsg());
  457. $mainframe->redirect( "index2.php?option=com_chronocontact" );
  458. }
  459. }
  460. $mainframe->redirect( "index2.php?option=com_chronocontact", 'We couldn\'t validate your key because of some wrong data used' );
  461. }else{
  462. if(trim(JRequest::getVar('instantcode'))){
  463. $step1 = base64_decode(trim(JRequest::getVar('instantcode')));
  464. $step2 = str_replace(substr(md5(str_replace('www.', '', strtolower($matches[2]))), 0, 7), '', $step1);
  465. $step3 = str_replace(substr(md5(str_replace('www.', '', strtolower($matches[2]))), - strlen(md5(str_replace('www.', '', strtolower($matches[2])))) + 7), '', $step2);
  466. $step4 = str_replace(substr($configs->get('licensecode', ''), 0, 10), '', $step3);
  467. $step5 = str_replace(substr($configs->get('licensecode', ''), - strlen($configs->get('licensecode', '')) + 10), '', $step4);
  468. //echo (int)$step5;return;
  469. //if((((int)$step5 + (24 * 60 * 60)) > strtotime(date('d-m-Y H:i:s')))||(((int)$step5 - (24 * 60 * 60)) < strtotime(date('d-m-Y H:i:s')))){
  470. if(((int)$step5 < (strtotime("now") + (24 * 60 * 60)))&&((int)$step5 > (strtotime("now") - (24 * 60 * 60)))){
  471. $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
  472. $database->setQuery( $query );
  473. $result = $database->loadObject();
  474. $newline = "\n";
  475. if($result){
  476. $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=1';
  477. $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
  478. if (!$database->query()) {
  479. JError::raiseWarning(100, $database->getErrorMsg());
  480. $mainframe->redirect( "index2.php?option=com_chronocontact" );
  481. }
  482. }
  483. $mainframe->redirect( "index2.php?option=com_chronocontact", 'Your key was validated successfully' );
  484. }else{
  485. $mainframe->redirect( "index2.php?option=com_chronocontact", 'Invalid instant code' );
  486. }
  487. }else{
  488. $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
  489. $database->setQuery( $query );
  490. $result = $database->loadObject();
  491. $newline = "\n";
  492. if($result){
  493. $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=0';
  494. $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
  495. if (!$database->query()) {
  496. JError::raiseWarning(100, $database->getErrorMsg());
  497. $mainframe->redirect( "index2.php?option=com_chronocontact" );
  498. }
  499. }
  500. $mainframe->redirect( "index2.php?option=com_chronocontact", 'We couldn\'t validate your key because your hosting server doesn\'t have neither the CURL library nor the fsockopen functions or they may exist but don\'t function properly, please contact your host admin to fix them or contact us <a href="http://www.chronoengine.com/contactus.html">here</a> Or at this email address : webmaster@chronoengine.com' );
  501. }
  502. }
  503. }
  504. function validationconnect($type, $host, $port='80', $path='/', $data=array()) {
  505. global $mainframe;
  506. $_err = 'lib sockets::'.__FUNCTION__.'(): ';
  507. $str = '';
  508. $d = array();
  509. switch($type) { case 'http': $type = ''; case 'ssl': continue; default: die($_err.'bad $type'); }
  510. if(!empty($data)){
  511. foreach($data as $k => $v){
  512. $strarr[] = urlencode($k).'='.urlencode($v);
  513. }
  514. }
  515. $str = implode('&', $strarr);
  516. $result = '';
  517. //echo $str;
  518. $fp = fsockopen($host, $port, $errno, $errstr, 30);
  519. if(!$fp){
  520. //$mainframe->redirect( "index2.php?option=com_chronocontact", $_err.$errstr.$errno);
  521. $result = 'error';
  522. //die($_err.$errstr.$errno);
  523. }else{
  524. fputs($fp, "POST $path HTTP/1.1\r\n");
  525. fputs($fp, "Host: $host\r\n");
  526. fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  527. fputs($fp, "Content-length: ".strlen($str)."\r\n");
  528. fputs($fp, "Connection: close\r\n\r\n");
  529. fputs($fp, $str."\r\n\r\n");
  530. while(!feof($fp)){
  531. $d[] = fgets($fp,4096);
  532. }
  533. fclose($fp);
  534. $result = $d[count($d) - 1];
  535. } return $result;
  536. }
  537. // Publishing of the entries
  538. function publishChronoContact( $cid, $publish, $option ) {
  539. global $mainframe;
  540. $database =& JFactory::getDBO();
  541. if (count( $cid ) < 1) {
  542. $action = $publish ? 'publish' : 'unpublish';
  543. JError::raiseWarning(100, 'Select a item to '.$action);
  544. $mainframe->redirect( "index2.php?option=$option" );
  545. }
  546. $cids = implode( ',', $cid );
  547. $database->setQuery( "UPDATE #__chrono_contact SET published=".$publish." WHERE id IN ($cids)");
  548. if (!$database->query()) {
  549. JError::raiseWarning(100, $database->getErrorMsg());
  550. $mainframe->redirect( "index2.php?option=$option" );
  551. }
  552. if (count( $cid ) == 1) {
  553. $row =& JTable::getInstance('chronocontact', 'Table');
  554. $row->checkin( $cid[0] );
  555. }
  556. $mainframe->redirect( "index2.php?option=$option" );
  557. }
  558. function editChronoContact( $id, $option ) {
  559. $database =& JFactory::getDBO();
  560. $row =& JTable::getInstance('chronocontact', 'Table');
  561. $row->load($id);
  562. HTML_ChronoContact::editChronoContact( $row, $option );
  563. }
  564. // deletion of entries
  565. function removeChronoContact( $cid, $option ) {
  566. global $mainframe;
  567. $database =& JFactory::getDBO();
  568. if (!is_array( $cid ) || count( $cid ) < 1) {
  569. JError::raiseWarning(100, 'Please select an entry to delete');
  570. $mainframe->redirect( "index2.php?option=$option" );
  571. }
  572. $cids = implode( ',', $cid );
  573. $database->setQuery( "DELETE FROM #__chrono_contact WHERE id IN ($cids)" );
  574. if (!$database->query()) {
  575. JError::raiseWarning(100, $database->getErrorMsg());
  576. $mainframe->redirect( "index2.php?option=$option" );
  577. }
  578. $database->setQuery( "DELETE FROM #__chrono_contact_emails WHERE formid IN ($cids)" );
  579. if (!$database->query()) {
  580. JError::raiseWarning(100, $database->getErrorMsg());
  581. $mainframe->redirect( "index2.php?option=$option" );
  582. }
  583. $mainframe->redirect( "index2.php?option=$option" );
  584. }
  585. function copyChronoContact( $id , $option ) {
  586. global $mainframe;
  587. $database =& JFactory::getDBO();
  588. $row =& JTable::getInstance('chronocontact', 'Table');
  589. $row->load($id);
  590. $row->id = '';
  591. if (!$row->store()) {
  592. JError::raiseWarning(100, $row->getError());
  593. $mainframe->redirect( "index2.php?option=$option" );
  594. }
  595. //copy emails
  596. $database->setQuery( "SELECT * FROM #__chrono_contact_emails WHERE formid='".$id."'" );
  597. $emails = $database->loadAssocList();
  598. //print_r($emails);
  599. foreach($emails as $email){
  600. $email['emailid'] = '';
  601. $email['formid'] = $row->id;
  602. $row2 =& JTable::getInstance('chronocontactemails', 'Table');
  603. if (!$row2->bind( $email )) {
  604. JError::raiseWarning(100, $row2->getError());
  605. $mainframe->redirect( "index2.php?option=$option" );
  606. }
  607. if (!$row2->store()) {
  608. JError::raiseWarning(100, $row2->getError());
  609. $mainframe->redirect( "index2.php?option=$option" );
  610. }
  611. }
  612. //copy plugins
  613. $database->setQuery( "SELECT * FROM #__chrono_contact_plugins WHERE form_id='".$id."'" );
  614. $plugins = $database->loadAssocList();
  615. //print_r($emails);
  616. foreach($plugins as $plugin){
  617. $plugin['id'] = '';
  618. $plugin['form_id'] = $row->id;
  619. $row3 =& JTable::getInstance('chronocontactplugins', 'Table');
  620. if (!$row3->bind( $plugin )) {
  621. JError::raiseWarning(100, $row3->getError());
  622. $mainframe->redirect( "index2.php?option=$option" );
  623. }
  624. if (!$row3->store()) {
  625. JError::raiseWarning(100, $row3->getError());
  626. $mainframe->redirect( "index2.php?option=$option" );
  627. }
  628. }
  629. $mainframe->redirect( "index2.php?option=".$option );
  630. }
  631. // save entry
  632. function saveChronoContact( $option, $task ) {
  633. global $mainframe;
  634. $database =& JFactory::getDBO();
  635. $row =& JTable::getInstance('chronocontact', 'Table');
  636. $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
  637. //$post = JRequest::getVar( 'description', '', 'post','string', _J_ALLOWRAW );
  638. if (!$row->bind( $post )) {
  639. JError::raiseWarning(100, $row->getError());
  640. $mainframe->redirect( "index2.php?option=$option" );
  641. }
  642. $params = JRequest::getVar( 'params', array(), 'post', 'array');
  643. if (is_array( $params )) {
  644. $txt = array();
  645. foreach ( $params as $k=>$v) {
  646. $txt[] = "$k=$v";
  647. }
  648. $plugins = JRequest::getVar( 'plugins', array(), 'post', 'array');
  649. $mplugins_order = JRequest::getVar( 'mplugins_order', array(), 'post', 'array');
  650. $plugins_enable = JRequest::getVar( 'plugins_enable', array(), 'post', 'array');
  651. $pluginslist = array();
  652. $mplugins_orderlist = array();
  653. foreach($plugins_enable as $k => $plugin_enable){
  654. if($plugin_enable == 1){
  655. $pluginslist[] = $plugins[$k];
  656. $mplugins_orderlist[] = $mplugins_order[$k];
  657. }
  658. }
  659. if(is_array( $plugins )){
  660. $txt[] = "plugins=".implode(",", $pluginslist);
  661. }
  662. if(is_array( $mplugins_order )){
  663. $txt[] = "mplugins_order=".implode(",", $mplugins_orderlist);
  664. }
  665. $tablenames = JRequest::getVar( 'tablenames', array(), 'post', 'array');
  666. if(is_array( $tablenames )){
  667. $txt[] = "tablenames=".implode(",",$tablenames);
  668. }
  669. $row->paramsall = implode( "\n", $txt );
  670. }
  671. $FieldsNamesTypes = generateFieldsNamesTypes($post["html"]);
  672. $row->fieldsnames = implode(",", $FieldsNamesTypes["names"]);
  673. $row->fieldstypes = implode(",", $FieldsNamesTypes["types"]);
  674. $row->dbclasses = "";
  675. if (is_array( $params )) {
  676. foreach($tablenames as $tablename){
  677. //Create Class
  678. $tables = array();
  679. $tables[] = $tablename;
  680. $result = $database->getTableFields( $tables, false );
  681. //print_r($result[$row->tablenames]);
  682. $table_fields = $result[$tablename];
  683. $row->dbclasses .= "<?php";
  684. $row->dbclasses .= "\n";
  685. $row->dbclasses .= "if (!class_exists('Table".str_replace($mainframe->getCfg('dbprefix'), '', $tablename)."')) {";
  686. $row->dbclasses .= "\n";
  687. $row->dbclasses .= "class Table".str_replace($mainframe->getCfg('dbprefix'), '', $tablename)." extends JTable {";
  688. $primary = 'id';
  689. foreach($table_fields as $table_field => $field_data){
  690. $row->dbclasses .= "\n";
  691. $row->dbclasses .= "var \$".$table_field." = null;";
  692. if($field_data->Key == 'PRI')$primary = $table_field;
  693. }
  694. $row->dbclasses .= "\n";
  695. $row->dbclasses .= "function __construct( &\$database ) {";
  696. $row->dbclasses .= "\n";
  697. $row->dbclasses .= "parent::__construct( '".$tablename."', '".$primary."', \$database );";
  698. $row->dbclasses .= "\n";
  699. $row->dbclasses .= "}";
  700. $row->dbclasses .= "\n";
  701. $row->dbclasses .= "}";
  702. $row->dbclasses .= "\n";
  703. $row->dbclasses .= "}";
  704. $row->dbclasses .= "\n";
  705. $row->dbclasses .= "?>";
  706. $row->dbclasses .= "\n";
  707. }
  708. }
  709. $row->autogenerated = "";
  710. //$tables = explode("," , $paramsvalues->tablenames);
  711. foreach($tablenames as $tablename){
  712. $row->autogenerated = $row->autogenerated.'<?php
  713. $MyForm =& CFChronoForm::getInstance("'.$post['name'].'");
  714. if($MyForm->formparams("dbconnection") == "Yes"){
  715. $user = JFactory::getUser();
  716. $row =& JTable::getInstance("'.str_replace($mainframe->getCfg("dbprefix"), "", $tablename).'", "Table");
  717. srand((double)microtime()*10000);
  718. $inum = "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
  719. JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
  720. JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
  721. JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
  722. JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
  723. $post = JRequest::get( "post" , JREQUEST_ALLOWRAW );
  724. if (!$row->bind( $post )) {
  725. JError::raiseWarning(100, $row->getError());
  726. }
  727. if (!$row->store()) {
  728. JError::raiseWarning(100, $row->getError());
  729. }
  730. $MyForm->tablerow["'.$tablename.'"] = $row;
  731. }
  732. ?>
  733. ';
  734. }
  735. if (!$row->store()) {
  736. JError::raiseWarning(100, $row->getError());
  737. $mainframe->redirect( "index2.php?option=$option" );
  738. }
  739. //Emails
  740. //Delet old emails and save new clean ones
  741. $database->setQuery( "DELETE FROM #__chrono_contact_emails WHERE formid = '".$row->id."'" );
  742. if (!$database->query()) {
  743. JError::raiseWarning(100, $database->getErrorMsg());
  744. $mainframe->redirect( "index2.php?option=$option" );
  745. }
  746. preg_match_all('/start_email{.*?}end_email/i', $post['emails_temp'], $matches);
  747. $emails = array();
  748. $template_count2 = 0;
  749. $emails_ids = explode(',', str_replace('email_', '', $post['emails_temp_ids']));
  750. foreach ( $matches[0] as $email ) {
  751. $template_count = $emails_ids[$template_count2+1];
  752. //echo $email;return;
  753. $email = preg_replace('/start_email{/i', '', $email);
  754. $email = preg_replace('/}end_email/i', '', $email);
  755. $email_elements = explode('||', $email);
  756. //$emails[] = trim($email);
  757. $post2 = array();
  758. //$post2['emailid'] = ;
  759. $post2['to'] = str_replace('TO=[', '', str_replace(']', '', $email_elements[0]));
  760. $post2['dto'] = str_replace('DTO=[', '', str_replace(']', '', $email_elements[1]));
  761. $post2['subject'] = str_replace('SUBJECT=[', '', str_replace(']', '', $email_elements[2]));
  762. $post2['dsubject'] = str_replace('DSUBJECT=[', '', str_replace(']', '', $email_elements[3]));
  763. $post2['cc'] = str_replace('CC=[', '', str_replace(']', '', $email_elements[4]));
  764. $post2['dcc'] = str_replace('DCC=[', '', str_replace(']', '', $email_elements[5]));
  765. $post2['bcc'] = str_replace('BCC=[', '', str_replace(']', '', $email_elements[6]));
  766. $post2['dbcc'] = str_replace('DBCC=[', '', str_replace(']', '', $email_elements[7]));
  767. $post2['fromname'] = str_replace('FROMNAME=[', '', str_replace(']', '', $email_elements[8]));
  768. $post2['dfromname'] = str_replace('DFROMNAME=[', '', str_replace(']', '', $email_elements[9]));
  769. $post2['fromemail'] = str_replace('FROMEMAIL=[', '', str_replace(']', '', $email_elements[10]));
  770. $post2['dfromemail'] = str_replace('DFROMEMAIL=[', '', str_replace(']', '', $email_elements[11]));
  771. $post2['replytoname'] = str_replace('REPLYTONAME=[', '', str_replace(']', '', $email_elements[12]));
  772. $post2['dreplytoname'] = str_replace('DREPLYTONAME=[', '', str_replace(']', '', $email_elements[13]));
  773. $post2['replytoemail'] = str_replace('REPLYTOEMAIL=[', '', str_replace(']', '', $email_elements[14]));
  774. $post2['dreplytoemail'] = str_replace('DREPLYTOEMAIL=[', '', str_replace(']', '', $email_elements[15]));
  775. $post2['formid'] = $row->id;
  776. //$post2['params'] = $post['params_email_'.$template_count];
  777. $params = explode(",", $post['params_email_'.$template_count]);
  778. $txt = array();
  779. $txt[0] = "recordip=".$params[0];
  780. $txt[1] = "emailtype=".$params[1];
  781. $txt[2] = "enabled=".$params[2];
  782. $txt[3] = "editor=".$params[3];
  783. $txt[4] = "enable_attachments=".$params[4];
  784. $post2['params'] = implode("\n", $txt);
  785. $post2['template'] = trim($post['editor_email_'.$template_count]) ? trim($post['editor_email_'.$template_count]) : generateAutoEmailTemplate($post['html']);
  786. $template_count2++;
  787. $post2['enabled'] = $params[2];
  788. $row2 =& JTable::getInstance('chronocontactemails', 'Table');
  789. if (!$row2->bind( $post2 )) {
  790. JError::raiseWarning(100, $row2->getError());
  791. $mainframe->redirect( "index2.php?option=$option" );
  792. }
  793. if (!$row2->store()) {
  794. JError::raiseWarning(100, $row2->getError());
  795. $mainframe->redirect( "index2.php?option=$option" );
  796. }
  797. }
  798. //end Emails
  799. if($task != 'applychanges'){
  800. $mainframe->redirect( "index2.php?option=".$option );
  801. }else{
  802. editChronoContact( $row->id, $option );
  803. }
  804. }
  805. // abort the current action
  806. function cancelChronoContact( $option ) {
  807. global $mainframe;
  808. $database =& JFactory::getDBO();
  809. //$row =& JTable::getInstance('chronocontact', 'Table');
  810. //$row->bind( $_POST );
  811. //$row->checkin();
  812. $mainframe->redirect( "index2.php?option=$option" );
  813. }
  814. // list entries
  815. function showChronoContact($option) {
  816. global $mainframe;
  817. $limit = $mainframe->getUserStateFromRequest($option.'.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
  818. $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int');
  819. // count entries
  820. $database =& JFactory::getDBO();
  821. $database->setQuery( "SELECT count(*) FROM #__chrono_contact" );
  822. $total = $database->loadResult();
  823. echo $database->getErrorMsg();
  824. jimport('joomla.html.pagination');
  825. $pageNav = new JPagination($total, $limitstart, $limit);
  826. # main database query
  827. $database->setQuery( "SELECT * FROM #__chrono_contact ORDER BY id LIMIT $pageNav->limitstart,$pageNav->limit" );
  828. $rows = $database->loadObjectList();
  829. if ($database->getErrorNum()) {
  830. JError::raiseWarning(100, $database->stderr());
  831. $mainframe->redirect( "index2.php?option=$option" );
  832. }
  833. HTML_ChronoContact::showChronoContact( $rows, $pageNav, $option );
  834. }
  835. ///////////////////////////////
  836. function showdataChronoContact($id, $option) {
  837. global $mainframe;
  838. $database =& JFactory::getDBO();
  839. if(!$id){
  840. if(is_array(JRequest::getVar('formid', array(0), 'post', 'array'))){
  841. $id_arr = JRequest::getVar('formid', array(0), 'post', 'array');
  842. $id = $id_arr[0];
  843. }else{
  844. $id = JRequest::getVar('formid', 0, 'post', 'int');
  845. }
  846. }
  847. if(!$id){
  848. $id = JRequest::getVar('formid', 0, 'get', 'int');
  849. }
  850. if($id){
  851. $query = "SELECT * FROM #__chrono_contact WHERE id = '$id'";
  852. $database->setQuery( $query );
  853. $rows = $database->loadObjectList();
  854. $paramsvalues = new JParameter($rows[0]->paramsall);
  855. $formtables = explode(",", $paramsvalues->get('tablenames'));
  856. }
  857. $table = JRequest::getVar('table', '');
  858. $result = $database->getTableList();
  859. if(!in_array($table, $result) || !$table){
  860. echo "<form action=\"index2.php\" method=\"post\" name=\"adminForm\">
  861. Table Doesn't Exist
  862. <input type=\"hidden\" name=\"task\" value=\"\" />
  863. <input type=\"hidden\" name=\"option\" value=\"$option\" />
  864. </form>";
  865. }else{
  866. $limit = $mainframe->getUserStateFromRequest($option.'.limit'.$table, 'limit', $mainframe->getCfg('list_limit'), 'int');
  867. $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart'.$table, 'limitstart', 0, 'int');
  868. // count entries
  869. $database->setQuery( "SELECT count(*) FROM ".$table );
  870. $total = $database->loadResult();
  871. echo $database->getErrorMsg();
  872. jimport('joomla.html.pagination');
  873. $pageNav = new JPagination($total, $limitstart, $limit);
  874. # main database query
  875. # get primary key
  876. $tables = array();
  877. $tables[] = $table;
  878. $result = $database->getTableFields( $tables, false );
  879. $table_fields = $result[$table];
  880. $primary = '';
  881. foreach($table_fields as $table_field => $field_data){
  882. if($field_data->Key == 'PRI')$primary = $table_field;
  883. }
  884. $order = "";
  885. if($primary) $order = " ORDER BY ".$primary;
  886. $database->setQuery( "SELECT * FROM ".$table.$order." LIMIT $pageNav->limitstart,$pageNav->limit" );
  887. $rows = $database->loadObjectList();
  888. if ($database->getErrorNum()) {
  889. JError::raiseWarning(100, $database->stderr());
  890. $mainframe->redirect( "index2.php?option=$option" );
  891. }
  892. $formid = $id;
  893. HTML_ChronoContact::showdataChronoContact( $rows, $pageNav, $option, $formid, $table );
  894. }
  895. }
  896. function viewdataChronoContact( $ids, $option ) {
  897. global $mainframe;
  898. $database =& JFactory::getDBO();
  899. $fids = explode("_",$ids);
  900. $table = JRequest::getVar('table', '', 'post', 'string', 0);
  901. # get primary key
  902. $tables = array();
  903. $tables[] = $table;
  904. $result = $database->getTableFields( $tables, false );
  905. $table_fields = $result[$table];
  906. $primary = 'cf_id';
  907. foreach($table_fields as $table_field => $field_data){
  908. if($field_data->Key == 'PRI')$primary = $table_field;
  909. }
  910. $database->setQuery( "SELECT * FROM ".$table." WHERE ".$primary."=".$fids[0] );
  911. $rows = $database->loadObjectList();
  912. $row = $rows[0];
  913. $tablename = $table;
  914. //echo "SELECT * FROM ".$table." WHERE ".$primary."=".$fids[0];
  915. HTML_ChronoContact::viewdataChronoContact( $row, $option, $tablename, $fids[1] );
  916. }
  917. function tablemanagerChronoContact( $option ){
  918. global $mainframe;
  919. $database =& JFactory::getDBO();
  920. $result = $database->getTableList();
  921. HTML_ChronoContact::tablemanagerChronoContact($option, $result);
  922. }
  923. function maketableChronoContact( $id, $option ) {
  924. global $mainframe;
  925. $database =& JFactory::getDBO();
  926. $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
  927. $database->setQuery( $query );
  928. $result = $database->loadObject();
  929. //$configs = JComponentHelper::getParams('com_chronocontact');
  930. $configs = new JParameter($result->params);
  931. $table = JRequest::getVar('table');
  932. $result = $database->getTableList();
  933. if ($table) {
  934. $tables = array();
  935. $tables[] = $table;
  936. $result = $database->getTableFields( $tables, false );
  937. $table_fields = $result[$table];
  938. $row = new StdClass();
  939. $row->id = 0;
  940. HTML_ChronoContact::maketableChronoContact( $row, $option, $table, $table_fields );
  941. } else {
  942. $row =& JTable::getInstance('chronocontact', 'Table');
  943. $row->load( $id );
  944. $html_message = "";
  945. $multipagefields = '';
  946. $multipagefieldsnames = array();
  947. //check if form is a mother form and load childs fields
  948. $formparams = new JParameter($row->paramsall);
  949. $formplugins = explode(",", $formparams->get('plugins'));
  950. if(in_array('cf_multi_page', $formplugins)){
  951. $query = "SELECT * FROM #__chrono_contact_plugins WHERE `form_id` = '".$id."' AND name='cf_multi_page'";
  952. $database->setQuery( $query );
  953. $multipageconfig = $database->loadObject();
  954. $multipageparams = new JParameter($multipageconfig->params);
  955. $multipageforms = array();
  956. if(trim($multipageparams->get('formsnames'))){
  957. $multipageforms = explode(',', $multipageparams->get('formsnames'));
  958. $multipagefieldsnames = array();
  959. $multipagefields = array();
  960. }
  961. foreach($multipageforms as $multipageform){
  962. $query = "SELECT * FROM #__chrono_contact WHERE `name` = '".$multipageform."'";
  963. $database->setQuery( $query );
  964. $multipageformdata = $database->loadObject();
  965. $multipagefields[] = $multipageformdata->fieldsnames;
  966. }
  967. $multipagefieldsnames = explode(",", implode(",", $multipagefields));
  968. }
  969. $defaults = array('cf_id' => (object) array('Type' => 'INT(11)', 'Key' => 'PRI', 'Extra' => 'auto_increment'),
  970. 'uid' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''),
  971. 'recordtime' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''),
  972. 'ipaddress' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''),
  973. 'cf_user_id' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''));
  974. $names = array();
  975. if(trim($row->fieldsnames)){
  976. $names = explode(",", $row->fieldsnames);
  977. }
  978. $fieldstypes = explode(",", $row->fieldstypes);
  979. foreach($names as $name){
  980. $defaults[$name] = (object) array('Type' => '', 'Key' => '', 'Extra' => '');
  981. }
  982. if(count($multipagefieldsnames)){
  983. foreach($multipagefieldsnames as $multipagefieldsname){
  984. $defaults[$multipagefieldsname] = (object) array('Type' => '', 'Key' => '', 'Extra' => '');
  985. }
  986. }
  987. HTML_ChronoContact::maketableChronoContact( $row, $option, '', $defaults );
  988. }
  989. }
  990. function finalizetableChronoContact( $option ) {
  991. global $mainframe;
  992. $database =& JFactory::getDBO();
  993. $id = JRequest::getVar('formid');
  994. $table = JRequest::getVar('istable_name');
  995. $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
  996. $table_sql_arr = array();
  997. $primarykey = '';
  998. if($id){
  999. $row =& JTable::getInstance('chronocontact', 'Table');
  1000. $row->load( $id );
  1001. $paramsvalues = new JParameter($row->paramsall);
  1002. if(is_array($post['fields'])){
  1003. foreach($post['fields'] as $k => $field){
  1004. if($field && $post['fields_enable'][$k]){
  1005. $sqlpiece = '`'.$field.'` '.$post['fields_types'][$k].' NOT NULL';
  1006. if(JRequest::getVar('isautoincrement') == $field){
  1007. $sqlpiece .= " auto_increment";
  1008. }
  1009. if(JRequest::getVar('iskey') == $field){
  1010. $primarykey = "PRIMARY KEY (`".$field."`)";
  1011. }
  1012. $table_sql_arr[] = $sqlpiece;
  1013. }
  1014. }
  1015. }
  1016. if($primarykey){
  1017. $table_sql_arr[] = $primarykey;
  1018. }
  1019. if ( count($post['fields']) > 0){
  1020. $table_sql = "CREATE TABLE `".JRequest::getVar('istable_name')."` (";
  1021. $table_sql .= implode(", ", $table_sql_arr);
  1022. if ($paramsvalues->get('mysql_type', 0) == 2){
  1023. $table_sql .= ") TYPE = MYISAM ;";
  1024. } else{
  1025. $table_sql .= ") ENGINE = MYISAM ;";
  1026. }
  1027. }
  1028. }else{
  1029. if($table){
  1030. $result = $database->getTableList();
  1031. $table_sql = '';
  1032. if(in_array(JRequest::getVar('tableexists'), $result)){
  1033. //rename table if name was changed
  1034. if($table != JRequest::getVar('tableexists')){
  1035. $database->setQuery('RENAME TABLE `'.JRequest::getVar('tableexists').'` TO `'.$table.'`');
  1036. if (!$database->query()) {
  1037. $mainframe->redirect( 'index2.php?option='.$option, "Error while renaming table :".$database->getErrorMsg() );
  1038. }
  1039. }
  1040. $tables = array();
  1041. $tables[] = $table;
  1042. $result = $database->getTableFields( $tables, false );
  1043. $table_fields = $result[$table];
  1044. if(is_array($post['fields'])){
  1045. foreach($post['fields'] as $k => $field){
  1046. $found = false;
  1047. $sqlpiece = '';
  1048. if($field && $post['fields_enable'][$k]){
  1049. foreach($table_fields as $fieldname => $fielddata){
  1050. if($field == $fieldname){
  1051. $found = true;
  1052. break;
  1053. }
  1054. }
  1055. if(!$found){
  1056. $sqlpiece = 'ADD COLUMN `'.$field.'` '.$post['fields_types'][$k].' NOT NULL';
  1057. }
  1058. if((JRequest::getVar('isautoincrement') == $field)&&$sqlpiece){
  1059. $sqlpiece .= " auto_increment";
  1060. }
  1061. if((JRequest::getVar('iskey') == $field)&&(JRequest::getVar('isoldkey') != $field)){
  1062. $primarykey = "DROP PRIMARY KEY, ADD PRIMARY KEY (`".$field."`)";
  1063. }
  1064. if($sqlpiece){
  1065. $table_sql_arr[] = $sqlpiece;
  1066. }
  1067. }
  1068. if($field && !$post['fields_enable'][$k] && in_array($field, array_keys($table_fields))){
  1069. $table_sql_arr[] = 'DROP `'.$field.'`';
  1070. }
  1071. }
  1072. if($primarykey){
  1073. $table_sql_arr[] = $primarykey;
  1074. }
  1075. if(implode(", ", $table_sql_arr)){
  1076. $table_sql = 'ALTER TABLE '.$table.' '.implode(", ", $table_sql_arr).';';
  1077. }
  1078. }
  1079. }
  1080. }
  1081. }
  1082. $success_message = ($id) ? "Table has been created successfully" : "Table has been updated successfully";
  1083. if($table_sql){
  1084. $database->setQuery( $table_sql );
  1085. if (!$database->query()) {
  1086. $mainframe->redirect( 'index2.php?option='.$option, "Error while creating table :".$database->getErrorMsg() );
  1087. }else{
  1088. $mainframe->redirect( 'index2.php?option='.$option, $success_message );
  1089. }
  1090. }else{
  1091. $mainframe->redirect( 'index2.php?option='.$option, "Your changes have been applied" );
  1092. }
  1093. }
  1094. function updatetablelistChronoContact( $option ) {
  1095. global $mainframe;
  1096. $database =& JFactory::getDBO();
  1097. $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
  1098. $table_sql_arr = array();
  1099. if(is_array($post['tables'])){
  1100. foreach($post['tables'] as $k => $table){
  1101. if($table && !$post['tables_enable'][$k]){
  1102. $sqlpiece = '`'.$table.'`';
  1103. $table_sql_arr[] = $sqlpiece;
  1104. }
  1105. }
  1106. }
  1107. if(count($table_sql_arr)){
  1108. $table_sql = 'DROP TABLE IF EXISTS '.implode(", ", $table_sql_arr).';';
  1109. $database->setQuery( $table_sql );
  1110. if (!$database->query()) {
  1111. $mainframe->redirect( 'index2.php?option='.$option, "Error:".$database->getErrorMsg() );
  1112. }else{
  1113. $mainframe->redirect( 'index2.php?option='.$option, "Tables list updated successfully" );
  1114. }
  1115. }else{
  1116. $mainframe->redirect( 'index2.php?option='.$option, "No changes have been made" );
  1117. }
  1118. }
  1119. /* backup ****************************************************/
  1120. function backupChronoContact( $id, $option, $task ){
  1121. global $mainframe;
  1122. $database =& JFactory::getDBO();
  1123. if($task == 'backup'){
  1124. $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$id."'" );
  1125. $rows = $database->loadObjectList();
  1126. $tablename = $mainframe->getCfg('dbprefix')."chrono_contact";
  1127. $tables = array( $tablename );
  1128. $result = $database->getTableFields( $tables );
  1129. $table_fields = array_keys($result[$tablename]);
  1130. $string = '';
  1131. foreach($table_fields as $table_field){
  1132. $string .= '<++-++-++'.$table_field.'++-++-++>';
  1133. $string .= $rows[0]->$table_field;
  1134. $string .= '<endendend>';
  1135. }
  1136. $database->setQuery( "SELECT * FROM #__chrono_contact_emails WHERE formid='".$id."' ORDER BY emailid" );
  1137. $emails = $database->loadObjectList();
  1138. $tablename = $mainframe->getCfg('dbprefix')."chrono_contact_emails";
  1139. $tables = array( $tablename );
  1140. $result = $database->getTableFields( $tables );
  1141. $table_fields = array_keys($result[$tablename]);
  1142. $string2 = '';
  1143. foreach($emails as $email){
  1144. foreach($table_fields as $table_field){
  1145. $string2 .= '<2++-++-++'.$table_field.'++-++-++>';
  1146. $string2 .= $email->$table_field;
  1147. $string2 .= '<endendend2>';
  1148. }
  1149. $string2 .= '<cf_email_separator>';
  1150. }
  1151. if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1152. $UserBrowser = "Opera";
  1153. }
  1154. elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1155. $UserBrowser = "IE";
  1156. } else {
  1157. $UserBrowser = '';
  1158. }
  1159. $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
  1160. @ob_end_clean();
  1161. ob_start();
  1162. header('Content-Type: ' . $mime_type);
  1163. header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  1164. if ($UserBrowser == 'IE') {
  1165. header('Content-Disposition: inline; filename="' . $rows[0]->name.'.cfbak"');
  1166. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1167. header('Pragma: public');
  1168. }
  1169. else {
  1170. header('Content-Disposition: attachment; filename="' . $rows[0]->name.'.cfbak"');
  1171. header('Pragma: no-cache');
  1172. }
  1173. print $string.'
  1174. {cfbak_start_emails}
  1175. '.$string2.'
  1176. {cfbak_end_emails}';
  1177. exit();
  1178. }else{
  1179. $doc = new DomDocument('1.0', 'UTF-8');
  1180. $root = $doc->createElement('root');
  1181. $root = $doc->appendChild($root);
  1182. $database->setQuery( "SELECT * FROM #__chrono_contact" );
  1183. $forms = $database->loadObjectList();
  1184. $tablename = $mainframe->getCfg('dbprefix')."chrono_contact";
  1185. $tables = array( $tablename );
  1186. $result = $database->getTableFields( $tables );
  1187. $table_fields = array_keys($result[$tablename]);
  1188. foreach($forms as $form){
  1189. $occ = $doc->createElement("form_".$form->name);
  1190. $occ = $root->appendChild($occ);
  1191. foreach($table_fields as $table_field){
  1192. $child = $doc->createElement($table_field);
  1193. $child = $occ->appendChild($child);
  1194. $value = $doc->createTextNode($form->$table_field);
  1195. $value = $child->appendChild($value);
  1196. }
  1197. //list emails
  1198. $database->setQuery( "SELECT * FROM #__chrono_contact_emails WHERE formid='".$form->id."' ORDER BY emailid" );
  1199. $emails = $database->loadObjectList();
  1200. $tablename_email = $mainframe->getCfg('dbprefix')."chrono_contact_emails";
  1201. $tables_email = array( $tablename_email );
  1202. $result_email = $database->getTableFields( $tables_email );
  1203. $table_fields_email = array_keys($result_email[$tablename_email]);
  1204. $child = $doc->createElement("emails");
  1205. $child = $occ->appendChild($child);
  1206. foreach($emails as $email){
  1207. $occ_email = $doc->createElement("email".$email->emailid);
  1208. $occ_email = $child->appendChild($occ_email);
  1209. foreach($table_fields_email as $table_field_email){
  1210. $child_email = $doc->createElement($table_field_email);
  1211. $child_email = $occ_email->appendChild($child_email);
  1212. $value_email = $doc->createTextNode($email->$table_field_email);
  1213. $value_email = $child_email->appendChild($value_email);
  1214. }
  1215. }
  1216. //list plugins
  1217. $database->setQuery( "SELECT * FROM #__chrono_contact_plugins WHERE id='".$form->id."' ORDER BY id" );
  1218. $plugins = $database->loadObjectList();
  1219. $tablename_plugin = $mainframe->getCfg('dbprefix')."chrono_contact_plugins";
  1220. $tables_plugin = array( $tablename_plugin );
  1221. $result_plugin = $database->getTableFields( $tables_plugin );
  1222. $table_fields_plugin = array_keys($result_plugin[$tablename_plugin]);
  1223. $child = $doc->createElement("plugins");
  1224. $child = $occ->appendChild($child);
  1225. foreach($plugins as $plugin){
  1226. $occ_plugin = $doc->createElement($plugin->name);
  1227. $occ_plugin = $child->appendChild($occ_plugin);
  1228. foreach($table_fields_plugin as $table_field_plugin){
  1229. $child_plugin = $doc->createElement($table_field_plugin);
  1230. $child_plugin = $occ_plugin->appendChild($child_plugin);
  1231. $value_plugin = $doc->createTextNode($plugin->$table_field_plugin);
  1232. $value_plugin = $child_plugin->appendChild($value_plugin);
  1233. }
  1234. }
  1235. }
  1236. $xml_string = $doc->saveXML();
  1237. if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1238. $UserBrowser = "Opera";
  1239. }
  1240. elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1241. $UserBrowser = "IE";
  1242. } else {
  1243. $UserBrowser = '';
  1244. }
  1245. $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
  1246. @ob_end_clean();
  1247. ob_start();
  1248. header('Content-Type: ' . $mime_type);
  1249. header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  1250. if ($UserBrowser == 'IE') {
  1251. header('Content-Disposition: inline; filename="' . "ALL_".date('d_M_Y_H:i:s').'.cfxbak"');
  1252. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1253. header('Pragma: public');
  1254. }
  1255. else {
  1256. header('Content-Disposition: attachment; filename="' . "ALL_".date('d_M_Y_H:i:s').'.cfxbak"');
  1257. header('Pragma: no-cache');
  1258. }
  1259. print $xml_string;
  1260. exit();
  1261. }
  1262. /*if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1263. $UserBrowser = "Opera";
  1264. }
  1265. elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1266. $UserBrowser = "IE";
  1267. } else {
  1268. $UserBrowser = '';
  1269. }
  1270. $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
  1271. @ob_end_clean();
  1272. ob_start();
  1273. header('Content-Type: ' . $mime_type);
  1274. header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  1275. if ($UserBrowser == 'IE') {
  1276. header('Content-Disposition: inline; filename="' . $rows[0]->name.'.cfbak"');
  1277. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1278. header('Pragma: public');
  1279. }
  1280. else {
  1281. header('Content-Disposition: attachment; filename="' . $rows[0]->name.'.cfbak"');
  1282. header('Pragma: no-cache');
  1283. }
  1284. print $string.'
  1285. {cfbak_start_emails}
  1286. '.$string2.'
  1287. {cfbak_end_emails}';
  1288. exit();
  1289. */
  1290. }
  1291. function restore1ChronoContact( $id, $option ){
  1292. HTML_ChronoContact::restoreChronoContact( $id, $option );
  1293. }
  1294. function restore2ChronoContact( $id, $option ){
  1295. global $mainframe;
  1296. $database =& JFactory::getDBO();
  1297. jimport('joomla.utilities.error');
  1298. jimport('joomla.filesystem.file');
  1299. $id = JRequest::getVar('formid');
  1300. //echo $_FILES['file']['type'];
  1301. if(is_array(JRequest::getVar( 'file', '', 'files', 'array' ))){
  1302. $file = JRequest::getVar( 'file', '', 'files', 'array' );
  1303. $filename = $file['name'];
  1304. $exten = explode(".",$filename);
  1305. if($exten[count($exten)-1] == 'cfbak'){
  1306. //if($_FILES['file']['type'] == "application/octet-stream"){
  1307. //$filename = $_FILES['file']['name'];
  1308. $path = JPATH_BASE.DS.'cache';
  1309. $uploadedfile = JFile::upload($file['tmp_name'], $path.DS.$filename);
  1310. //if( is_writable($path) ) {
  1311. if(!$uploadedfile) {
  1312. print "<font class=\"error\">"."UPLAOD FAILED".": " . $file['error'] . "</font><br>\n";
  1313. JError::raiseWarning(100, "UPLAOD FAILED".": " . $file['error']);
  1314. $mainframe->redirect( "index2.php?option=$option" );
  1315. } else {
  1316. $data = file_get_contents( $path.DS.$filename );
  1317. $data = str_replace( '&amp;', '&', $data );
  1318. $values = '(';
  1319. $values2 = '(';
  1320. //print $data;
  1321. preg_match_all('/\<++(.*?)\<endendend>/s', $data, $matches);
  1322. $i = 0;
  1323. foreach ( $matches[0] as $match ) {
  1324. if($i != 0){$values .= ',';$values2 .= ',';}
  1325. //echo $match.'x';
  1326. preg_match_all('/\<++(.*?)\++>/s', $match, $match2es);
  1327. $fieldvalue = str_replace($match2es[0][0],'',$match);
  1328. $match2es[0][0] = str_replace('<++-++-++','',$match2es[0][0]);
  1329. $match2es[0][0] = str_replace('++-++-++>','',$match2es[0][0]);
  1330. $values .= $match2es[0][0];
  1331. if($i == 0){
  1332. $values2 .= "''";
  1333. }else{
  1334. $match = str_replace('<++-++-++'.$match2es[0][0].'++-++-++>','',$match);
  1335. $match = str_replace('<endendend>','',$match);
  1336. $match = trim($match," \t.");
  1337. $values2 .= "'".addslashes($match)."'";
  1338. }
  1339. $i++;
  1340. }
  1341. $values .= ')';
  1342. $values2 .= ')';
  1343. $database->setQuery( "INSERT INTO #__chrono_contact ".$values." VALUES ".$values2 );
  1344. if (!$database->query()) {
  1345. JError::raiseWarning(100, "Restoring the whole form failed Failed, error : ".$database->getErrorMsg());
  1346. $mainframe->redirect( "index2.php?option=$option" );
  1347. }else{
  1348. //$mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
  1349. }
  1350. $lastformid = $database->insertid();
  1351. // Restore Emails
  1352. $values = '(`';
  1353. $values2 = '(';
  1354. $emails_data = array();
  1355. $emails_count = explode('<cf_email_separator>', $data);
  1356. $fields_count_1 = explode('{cfbak_start_emails}', $emails_count[0]);
  1357. $fields_count_2 = explode('<endendend2>', $fields_count_1[1]);
  1358. preg_match_all('/\<2++(.*?)\<endendend2>/s', $data, $matches);
  1359. $i = 0;
  1360. $i_v = 0;
  1361. $counter = 0;
  1362. foreach ( $matches[0] as $match ) {
  1363. preg_match_all('/\<2++(.*?)\++>/s', $match, $match2es);
  1364. $fieldvalue = str_replace($match2es[0][0],'',$match);
  1365. $match2es[0][0] = str_replace('<2++-++-++','',$match2es[0][0]);
  1366. $match2es[0][0] = str_replace('++-++-++>','',$match2es[0][0]);
  1367. if($i_v < (count($fields_count_2) - 1)){
  1368. if($i_v != 0){$values .= '`,`';}
  1369. $values .= $match2es[0][0];
  1370. }
  1371. if($i != 0){$values2 .= ',';}
  1372. if($i == 0){
  1373. $values2 .= "''";
  1374. }else if($i == 1){
  1375. $values2 .= "'".$lastformid."'";
  1376. }else{
  1377. $match = str_replace('<2++-++-++'.$match2es[0][0].'++-++-++>','',$match);
  1378. $match = str_replace('<endendend2>','',$match);
  1379. $match = trim($match," \t.");
  1380. $values2 .= "'".addslashes($match)."'";
  1381. }
  1382. $counter++;
  1383. $i++;
  1384. $i_v++;
  1385. if($counter == (count($fields_count_2) - 1)){
  1386. $values2 .= ')';
  1387. $emails_data[] = $values2;
  1388. $values2 = '(';
  1389. $counter = 0;
  1390. $i = 0;
  1391. }
  1392. }
  1393. $values .= '`)';
  1394. foreach($emails_data as $email_data){
  1395. $database->setQuery( "INSERT INTO #__chrono_contact_emails ".$values." VALUES ".$email_data );
  1396. if (!$database->query()) {
  1397. JError::raiseWarning(100, "Restoring Emails Setup Failed, error : ".$database->getErrorMsg());
  1398. $mainframe->redirect( "index2.php?option=$option" );
  1399. }else{
  1400. //$mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
  1401. }
  1402. }
  1403. $mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
  1404. }
  1405. //}
  1406. }else if($exten[count($exten)-1] == 'cfxbak'){
  1407. $path = JPATH_BASE.DS.'cache';
  1408. $uploadedfile = JFile::upload($file['tmp_name'], $path.DS.$filename);
  1409. if(!$uploadedfile) {
  1410. print "<font class=\"error\">"."UPLAOD FAILED".": " . $file['error'] . "</font><br>\n";
  1411. JError::raiseWarning(100, "UPLAOD FAILED".": " . $file['error']);
  1412. $mainframe->redirect( "index2.php?option=$option" );
  1413. } else {
  1414. $data = file_get_contents( $path.DS.$filename );
  1415. $data = str_replace( '&amp;', '&', $data );
  1416. $xml = simplexml_load_file($path.DS.$filename);
  1417. $post = array();
  1418. $post_email = array();
  1419. $post_plugin = array();
  1420. foreach($xml->children() as $form){
  1421. foreach($form->children() as $field){
  1422. $post[$field->getName()] = (string)$field;
  1423. if($field->getName() == 'emails'){
  1424. if(count($field->children())){
  1425. foreach($field->children() as $k => $email){
  1426. foreach($email->children() as $emaildata){
  1427. $post_email[$k][$emaildata->getName()] = (string)$emaildata;
  1428. }
  1429. }
  1430. }
  1431. }
  1432. if($field->getName() == 'plugins'){
  1433. if(count($field->children())){
  1434. foreach($field->children() as $k => $plugin){
  1435. foreach($plugin->children() as $plugindata){
  1436. $post_plugin[$k][$plugindata->getName()] = (string)$plugindata;
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. $row =& JTable::getInstance('chronocontact', 'Table');
  1443. $post['id'] = '';
  1444. if (!$row->bind( $post )) {
  1445. JError::raiseWarning(100, $row->getError());
  1446. $mainframe->redirect( "index2.php?option=$option" );
  1447. }
  1448. if (!$row->store()) {
  1449. JError::raiseWarning(100, $row->getError());
  1450. $mainframe->redirect( "index2.php?option=$option" );
  1451. }
  1452. foreach($post_email as $k => $email){
  1453. $email['formid'] = $row->id;
  1454. $email['emailid'] = '';
  1455. $row_email =& JTable::getInstance('chronocontactemails', 'Table');
  1456. if (!$row_email->bind( $email )) {
  1457. JError::raiseWarning(100, $row_email->getError());
  1458. $mainframe->redirect( "index2.php?option=$option" );
  1459. }
  1460. if (!$row_email->store()) {
  1461. JError::raiseWarning(100, $row_email->getError());
  1462. $mainframe->redirect( "index2.php?option=$option" );
  1463. }
  1464. }
  1465. foreach($post_plugin as $k => $plugin){
  1466. $plugin['form_id'] = $row->id;
  1467. $plugin['id'] = '';
  1468. $row_plugin =& JTable::getInstance('chronocontactplugins', 'Table');
  1469. if (!$row_plugin->bind( $plugin )) {
  1470. JError::raiseWarning(100, $row_plugin->getError());
  1471. $mainframe->redirect( "index2.php?option=$option" );
  1472. }
  1473. if (!$row_plugin->store()) {
  1474. JError::raiseWarning(100, $row_plugin->getError());
  1475. $mainframe->redirect( "index2.php?option=$option" );
  1476. }
  1477. }
  1478. $post = array();
  1479. $post_email = array();
  1480. $post_plugin = array();
  1481. }
  1482. $mainframe->redirect( 'index2.php?option='.$option , "Restored all data successfully");
  1483. }
  1484. }else{
  1485. echo "Sorry, But this is not a valid ChronoForms backup file, Backup files should end with .cfbak";
  1486. }
  1487. }
  1488. }
  1489. function BackupExcel( $id, $option ) {
  1490. global $mainframe;
  1491. $database =& JFactory::getDBO();
  1492. include_once JPATH_BASE.DS.'/components/com_chronocontact/excelwriter/'."Writer.php";
  1493. //echo $_POST['formid'];
  1494. $formid = JRequest::getVar( 'formid', array(), 'post', 'array');
  1495. $database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$formid[0]."'" );
  1496. $formname = $database->loadResult();
  1497. $tablename = JRequest::getVar('table');
  1498. $tables = array( $tablename );
  1499. $result = $database->getTableFields( $tables );
  1500. $table_fields = array_keys($result[$tablename]);
  1501. $database->setQuery( "SELECT * FROM ".$tablename."" );
  1502. $datarows = $database->loadObjectList();
  1503. $xls =& new Spreadsheet_Excel_Writer();
  1504. $xls->setVersion(8); // this fixes the 255 limit issue! :)
  1505. $xls->send("ChronoForms_".$formname."_".date("j_n_Y").".xls");
  1506. $format =& $xls->addFormat();
  1507. $format->setBold();
  1508. $format->setColor("blue");
  1509. if (strlen($formname) > 10){$formname = substr($formname,0,10);};
  1510. $sheet =& $xls->addWorksheet($formname.' at '.date("m-d-Y"));
  1511. $sheet->setInputEncoding('utf-8');
  1512. $titcol = 0;
  1513. foreach($table_fields as $table_field){
  1514. $sheet->writeString(0, $titcol, $table_field, $format);
  1515. $titcol++;
  1516. }
  1517. $datacol = 0;
  1518. $rowcount = 1;
  1519. foreach($datarows as $datarow){
  1520. foreach($table_fields as $table_field){
  1521. $sheet->writeString($rowcount, $datacol, $datarow->$table_field, 0);
  1522. $datacol++;
  1523. }
  1524. $datacol = 0;
  1525. $rowcount++;
  1526. }
  1527. $xls->close();
  1528. exit;
  1529. }
  1530. function deleterecordChronoContact( $cid_del, $option ) {
  1531. global $mainframe;
  1532. $database =& JFactory::getDBO();
  1533. //echo $cid_del[0];
  1534. $cid_del_arr = array();
  1535. foreach($cid_del as $cid_del_1){
  1536. $fids = explode("_",$cid_del_1);
  1537. $cid_del_arr[] = $fids[0];
  1538. $formid = $fids[1];
  1539. }
  1540. $cid_dels = implode( ',', $cid_del_arr );
  1541. if (!is_array( $cid_del ) || count( $cid_del ) < 1) {
  1542. JError::raiseWarning(100, 'Please select an entry to delete');
  1543. showdataChronoContact( $formid, $option );
  1544. }
  1545. # get primary key
  1546. $tables = array();
  1547. $table = JRequest::getVar('table');
  1548. $tables[] = $table;
  1549. $result = $database->getTableFields( $tables, false );
  1550. $table_fields = $result[$table];
  1551. $primary = 'cf_id';
  1552. foreach($table_fields as $table_field => $field_data){
  1553. if($field_data->Key == 'PRI')$primary = $table_field;
  1554. }
  1555. $database->setQuery( "DELETE FROM ".$table." WHERE ".$primary." IN ($cid_dels)" );
  1556. if (!$database->query()) {
  1557. JError::raiseWarning(100, $database->getErrorMsg());
  1558. showdataChronoContact( $formid, $option );
  1559. }
  1560. showdataChronoContact( $formid, $option );
  1561. }
  1562. function BackupCSV( $id, $option ) {
  1563. global $mainframe;
  1564. $database =& JFactory::getDBO();
  1565. include_once JPATH_BASE.'/components/com_chronocontact/excelwriter/'."Writer.php";
  1566. //echo $_POST['formid'];
  1567. $formid = JRequest::getVar( 'formid', array(), 'post', 'array');
  1568. $database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$formid[0]."'" );
  1569. $formname = $database->loadResult();
  1570. $tablename = JRequest::getVar('table');
  1571. $tables = array( $tablename );
  1572. $result = $database->getTableFields( $tables );
  1573. $table_fields = array_keys($result[$tablename]);
  1574. $database->setQuery( "SELECT * FROM ".$tablename."" );
  1575. $datarows = $database->loadObjectList();
  1576. $titcol = 0;
  1577. foreach($table_fields as $table_field){
  1578. if($titcol){$csvline .=",";}
  1579. $csvline .= $table_field;
  1580. $titcol++;
  1581. }
  1582. $csvline .="\n";
  1583. $datacol = 0;
  1584. $rowcount = 1;
  1585. foreach($datarows as $datarow){
  1586. foreach($table_fields as $table_field){
  1587. if($datacol){$csvline .=",";}
  1588. $csvline .= '"'.addslashes($datarow->$table_field).'"';
  1589. $datacol++;
  1590. }
  1591. $csvline .="\n";
  1592. $datacol = 0;
  1593. $rowcount++;
  1594. }
  1595. if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1596. $UserBrowser = "Opera";
  1597. }
  1598. elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
  1599. $UserBrowser = "IE";
  1600. } else {
  1601. $UserBrowser = '';
  1602. }
  1603. $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
  1604. @ob_end_clean();
  1605. ob_start();
  1606. header('Content-Type: ' . $mime_type);
  1607. header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  1608. if ($UserBrowser == 'IE') {
  1609. header('Content-Disposition: inline; filename="' . "ChronoForms - ".$formname." - ".date("j_n_Y").'.csv"');
  1610. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1611. header('Pragma: public');
  1612. }
  1613. else {
  1614. header('Content-Disposition: attachment; filename="' . "ChronoForms - ".$formname." - ".date("j_n_Y").'.csv"');
  1615. header('Pragma: no-cache');
  1616. }
  1617. print $csvline;
  1618. exit();
  1619. }
  1620. function deletetableChronoContact( $id, $option ){
  1621. global $mainframe;
  1622. $database =& JFactory::getDBO();
  1623. $result = $database->getTableList();
  1624. if (!in_array($mainframe->getCfg('dbprefix')."chronoforms_".$id, $result)) {
  1625. JError::raiseWarning(100, "There is no table for this form to delete");
  1626. $mainframe->redirect( "index2.php?option=$option" );
  1627. }else{
  1628. $database->setQuery( "DROP TABLE IF EXISTS `#__chronoforms_".$id."`;" );
  1629. if (!$database->query()) {
  1630. JError::raiseWarning(100, $database->getErrorMsg());
  1631. $mainframe->redirect( "index2.php?option=$option" );
  1632. }else{
  1633. $mainframe->redirect( 'index2.php?option='.$option , "Table Deleted successfully");
  1634. }
  1635. }
  1636. }
  1637. function menu_creator($option){
  1638. HTML_ChronoContact::menu_creator( $option );
  1639. }
  1640. function menu_save($option){
  1641. global $mainframe;
  1642. $database =& JFactory::getDBO();
  1643. JTable::addIncludePath(JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'database'.DS.'table');
  1644. $row =& JTable::getInstance('component', 'JTable');
  1645. //$row->load(1);
  1646. $row->name = JRequest::getVar('linktext');
  1647. $row->parent = JRequest::getVar('parent');
  1648. $row->ordering = JRequest::getVar('ordering');
  1649. $row->admin_menu_link = "option=com_chronocontact&task=show&formid=".JRequest::getVar('form_id');
  1650. $row->admin_menu_img = "js/ThemeOffice/".JRequest::getVar('icon');
  1651. $row->option = "com_chronocontact";
  1652. $row->link = "option=com_chronocontact&task=show&formid=1";
  1653. $row->admin_menu_alt = JRequest::getVar('linktext');
  1654. if (!$row->store()) {
  1655. JError::raiseWarning(100, $row->getError());
  1656. $mainframe->redirect( "index2.php?option=$option" );
  1657. }
  1658. $mainframe->redirect( 'index2.php?option='.$option , "Menu Item Created");
  1659. }
  1660. function menu_remover($option){
  1661. HTML_ChronoContact::menu_remover( $option );
  1662. }
  1663. function menu_delete( $cid, $option ){
  1664. global $mainframe;
  1665. $database =& JFactory::getDBO();
  1666. if (!is_array( $cid ) || count( $cid ) < 1) {
  1667. JError::raiseWarning(100, 'Please select an entry to delete');
  1668. $mainframe->redirect( "index2.php?option=$option" );
  1669. }
  1670. $cids = implode( ',', $cid );
  1671. $database->setQuery( "DELETE FROM #__components WHERE id IN ($cids)" );
  1672. if (!$database->query()) {
  1673. JError::raiseWarning(100, $database->getErrorMsg());
  1674. $mainframe->redirect( "index2.php?option=$option" );
  1675. }
  1676. $mainframe->redirect( 'index2.php?option='.$option.'&task=menu_remover' , "Menu Item Deleted");
  1677. }
  1678. function form_wizard($id, $option){
  1679. global $mainframe;
  1680. $htmloutput = '';
  1681. $database =& JFactory::getDBO();
  1682. $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$id."'" );
  1683. $row = $database->loadObject();
  1684. if($id){
  1685. if(!trim($row->chronocode)){
  1686. $mainframe->redirect( 'index2.php?option='.$option , "Sorry but this form was not created using the wizard");
  1687. }
  1688. define('CPHP_EOL', "\n");
  1689. $old_chrono_code = $row->chronocode;
  1690. $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode);
  1691. $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode);
  1692. $htmlcode = '';
  1693. $htmloutput = '';
  1694. //load theme
  1695. ob_start();
  1696. require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."wizardthemes".DS.'default'.DS."elements.php");
  1697. $theme_elements = ob_get_clean();
  1698. foreach($XHTMLELEMENTS as $XHTMLELEMENT){
  1699. if(trim($XHTMLELEMENT)){
  1700. $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT);
  1701. $thiselement = array();
  1702. $counter = 0;
  1703. foreach($element_pieces as $element_piece){
  1704. if(($element_piece != '{')&&($element_piece != '}')&&($counter > 0)){
  1705. $linepieces = explode(" = ", $element_piece);
  1706. if(count($linepieces) == 2){
  1707. $thiselement[trim($linepieces[0])] = $linepieces[1];
  1708. }else{
  1709. $thiselement[trim($linepieces[0])] = '';
  1710. }
  1711. }
  1712. $counter++;
  1713. }
  1714. //get element tag
  1715. $element_type = '';
  1716. if (preg_match("/\[type=\".*?\"/i", $element_pieces[0], $matches)) {
  1717. $element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]);
  1718. } else {
  1719. continue;
  1720. }
  1721. //get element from theme file
  1722. $element_theme_1 = explode("<!--start_".$element_type."-->", $theme_elements);
  1723. $element_theme_2 = explode("<!--end_".$element_type."-->", $element_theme_1[1]);
  1724. //fill the element theme
  1725. foreach($thiselement as $k => $v){
  1726. $element_theme_2[0] = str_replace('{cf_'.$k.'}', $v, $element_theme_2[0]);
  1727. }
  1728. if (preg_match("/<cf_theoptions>(.*?)<\/cf_theoptions>/is", $element_theme_2[0], $matches2)) {
  1729. //echo str_replace("<", "[", $matches2[0]);//$element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]);
  1730. $option_element = str_replace(array('<cf_theoptions>', '</cf_theoptions>') , array('', ''), $matches2[0]);
  1731. $options = explode("*,*" , $thiselement['theoptions']);
  1732. $optionsdata = '';
  1733. $icounter = 0;
  1734. foreach($options as $option){
  1735. if(trim($option)){
  1736. $optionsdata .= str_replace(array('{value}', '{title}', '{name}'), array($option, $option, str_replace(array('[',']'), array('', '') , $thiselement['name']).$icounter), $option_element);
  1737. $optionsdata .= CPHP_EOL;
  1738. $icounter++;
  1739. }
  1740. }
  1741. $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]);
  1742. }else if(preg_match("/<cf_thecells>(.*?)<\/cf_thecells>/is", $element_theme_2[0], $matches2)) {
  1743. $option_element = str_replace(array('<cf_thecells>', '</cf_thecells>') , array('', ''), $matches2[0]);
  1744. $options = explode("*,*" , $thiselement['thecells']);
  1745. $optionsdata = '';
  1746. $icounter = 0;
  1747. foreach($options as $option){
  1748. if(trim($option)){
  1749. $optionsdata .= str_replace(array('{value}'), array($option), $option_element);
  1750. $optionsdata .= CPHP_EOL;
  1751. $icounter++;
  1752. }
  1753. }
  1754. $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]);
  1755. } else{
  1756. //echo 'not found<br>';
  1757. }
  1758. $htmloutput .= $element_theme_2[0];
  1759. //add the tooltips and label styles
  1760. if(trim($thiselement['tooltiptext'])){
  1761. $htmloutput = str_replace("{cf_tooltip}", '<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" alt="" class="tooltipimg" src="components/com_chronocontact/css/images/tooltip.png"/></a>
  1762. <div class="tooltipdiv" style="display: none;">'.trim($thiselement['tooltiptext']).'</div>', $htmloutput);
  1763. }else{
  1764. $htmloutput = str_replace("{cf_tooltip}", "", $htmloutput);
  1765. }
  1766. if(trim($thiselement['tooltiptext'])){
  1767. $cf_tooltip2 = explode(" :: ", trim($thiselement['tooltiptext']));
  1768. $htmloutput = str_replace("{cf_tooltip2}", $cf_tooltip2[1], $htmloutput);
  1769. }else{
  1770. $htmloutput = str_replace("{cf_tooltip2}", "", $htmloutput);
  1771. }
  1772. if(($element_pieces[0] == '[type="cf_button"')){
  1773. if(trim($thiselement['reset']) == '1'){
  1774. $htmloutput = str_replace("{cf_resetbutton}", '<input type="reset" name="reset" value="Reset"/>', $htmloutput);
  1775. }else{
  1776. $htmloutput = str_replace("{cf_resetbutton}", "", $htmloutput);
  1777. }
  1778. }
  1779. if(trim($thiselement['hidelabel']) == '1'){
  1780. $htmloutput = str_replace("{cf_labeloptions}", ' style="display: none;"', $htmloutput);
  1781. }else if((trim($thiselement['labelwidth']) != 'auto')&&(trim($thiselement['labelwidth']) != '0px')){
  1782. $htmloutput = str_replace("{cf_labeloptions}", ' style="width: '.trim($thiselement['labelwidth']).';"', $htmloutput);
  1783. }else{
  1784. $htmloutput = str_replace("{cf_labeloptions}", "", $htmloutput);
  1785. }
  1786. if(($element_pieces[0] == '[type="cf_dropdown"')){
  1787. if((int)$thiselement['size'] > 1){
  1788. $htmloutput = str_replace("{cf_multiple}", 'multiple="multiple"', $htmloutput);
  1789. }else{
  1790. $htmloutput = str_replace("{cf_multiple}", '', $htmloutput);
  1791. }
  1792. }
  1793. if(($element_pieces[0] == '[type="cf_placeholder"')){
  1794. $database->setQuery( "SELECT * FROM #__chrono_contact_elements WHERE placeholder='".$thiselement['labeltext']."' ORDER BY id" );
  1795. $placeholder = $database->loadObject();
  1796. if($placeholder){
  1797. $htmloutput = str_replace("{cf_element_id}", $placeholder->id, $htmloutput);
  1798. $htmloutput = str_replace("{cf_params}", str_replace("\n", "*,*", $placeholder->params), $htmloutput);
  1799. $wizardelementparams = explode("\n", $placeholder->params);
  1800. $paramsatts = "";
  1801. foreach($wizardelementparams as $wizardelementparam){
  1802. if(trim($wizardelementparam)){
  1803. $paramdata = explode('=', $wizardelementparam);
  1804. $paramsatts .= $paramdata[0].'="'.$thiselement[$paramdata[0]].'" ';
  1805. }
  1806. }
  1807. $htmloutput = str_replace("{cf_params_elements}", $paramsatts, $htmloutput);
  1808. }else{
  1809. $htmloutput = str_replace("{cf_multiple}", '', $htmloutput);
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. HTML_ChronoContact::form_wizard( $htmloutput, $row, $option );
  1816. }
  1817. function save_form_wizard( $option ){
  1818. $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
  1819. if($post['formid'])$post['id'] = $post['formid'];
  1820. $post['html'] = $post['form_code_temp'];
  1821. $post['name'] = $post['form_title_temp'];
  1822. $post['redirecturl'] = $post['redirecturl'];
  1823. $post['onsubmitcode'] = $post['onsubmitcode'];
  1824. if(!$post['formid']){
  1825. $params = array();
  1826. $params[] = "formmethod=post";
  1827. $params[] = "omittedfields=";
  1828. $params[] = "LoadFiles=Yes";
  1829. $params[] = "submissions_limit=";
  1830. $params[] = "tablenames=";
  1831. $params[] = "savedataorder=";
  1832. $params[] = "handlepostedarrays=";
  1833. $params[] = "debug=0";
  1834. $params[] = "mysql_type=1";
  1835. $params[] = "enmambots=No";
  1836. $params[] = "uploads=".($post['uploadfields'] ? 'Yes' : 'No')."";
  1837. $params[] = "uploadfields=".$post['uploadfields']."";
  1838. $params[] = "uploadmax=";
  1839. $params[] = "uploadmin=";
  1840. $params[] = "uploadpath=";
  1841. $params[] = "dvfields=";
  1842. $params[] = "dvrecord=Record #n";
  1843. $params[] = "imagever=No";
  1844. $params[] = "imtype=0";
  1845. $params[] = "captcha_dataload=0";
  1846. $params[] = "imgver_error_msg=";
  1847. $params[] = "validate=No";
  1848. $params[] = "servervalidate=";
  1849. $params[] = "validatetype=mootools";
  1850. $params[] = "val_required=";
  1851. $params[] = "val_validate_number=";
  1852. $params[] = "val_validate_digits=";
  1853. $params[] = "val_validate_alpha=";
  1854. $params[] = "val_validate_alphanum=";
  1855. $params[] = "val_validate_date=";
  1856. $params[] = "val_validate_email=";
  1857. $params[] = "val_validate_url=";
  1858. $params[] = "val_validate_date_au=";
  1859. $params[] = "val_validate_currency_dollar=";
  1860. $params[] = "val_validate_selection=";
  1861. $params[] = "val_validate_one_required=";
  1862. $params[] = "val_validate_confirmation=";
  1863. $params[] = "plugins=";
  1864. $params[] = "plugins_order=1";
  1865. $params[] = "onsubmitcode_order=2";
  1866. $params[] = "autogenerated_order=3";
  1867. $params[] = "mplugins_order=";
  1868. $params[] = "dbconnection=";
  1869. $params[] = "datefieldformat=d/m/Y";
  1870. $params[] = "datefieldsnames=".$post['datefieldsnames'];
  1871. $post['paramsall'] = implode("\n", $params);
  1872. }else{
  1873. $params = JRequest::getVar( 'params', array(), 'post', 'array');
  1874. if (is_array( $params )) {
  1875. $txt = array();
  1876. if($post['uploadfields']){
  1877. $params['uploads'] = 'Yes';
  1878. $params['uploadfields'] = $post['uploadfields'];
  1879. $params['LoadFiles'] = 'Yes';
  1880. }
  1881. foreach ( $params as $k=>$v) {
  1882. if($k == 'datefieldsnames')$v = $post['datefieldsnames'];
  1883. $txt[] = "$k=$v";
  1884. }
  1885. $post['paramsall'] = implode( "\n", $txt );
  1886. }
  1887. }
  1888. //print_r($post);
  1889. global $mainframe;
  1890. $database =& JFactory::getDBO();
  1891. $row =& JTable::getInstance('chronocontact', 'Table');
  1892. if (!$row->bind( $post )) {
  1893. JError::raiseWarning(100, $row->getError());
  1894. $mainframe->redirect( "index2.php?option=$option" );
  1895. }
  1896. //auto transform to default
  1897. //defined('PHP_EOL') or define('PHP_EOL', '\r\n');
  1898. define('CPHP_EOL', "\n");
  1899. $old_chrono_code = $row->chronocode;
  1900. $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode);
  1901. $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode);
  1902. $htmlcode = '';
  1903. $htmloutput = '';
  1904. $emailoutput = '';
  1905. //load theme
  1906. ob_start();
  1907. require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.'default'.DS."elements.php");
  1908. $theme_elements = ob_get_clean();
  1909. ob_start();
  1910. require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.'default'.DS."email.php");
  1911. $email_template = ob_get_clean();
  1912. $WizardOutput = GetWizardOutput($XHTMLELEMENTS, $theme_elements, $email_template);
  1913. $OmittedElements = $WizardOutput['omitted'];
  1914. foreach($OmittedElements as $OmittedElement){
  1915. $WizardOutput['theme'][$OmittedElement] = '';
  1916. }
  1917. $htmloutput = implode('', $WizardOutput['theme']);
  1918. $emailoutput = implode('', $WizardOutput['email']);
  1919. $row->html = $htmloutput;
  1920. $row->chronocode = $old_chrono_code;
  1921. $FieldsNamesTypes = generateFieldsNamesTypes($row->html);
  1922. $row->fieldsnames = implode(",", $FieldsNamesTypes["names"]);
  1923. $row->fieldstypes = implode(",", $FieldsNamesTypes["types"]);
  1924. //end auto transform
  1925. if (!$row->store()) {
  1926. JError::raiseWarning(100, $row->getError());
  1927. $mainframe->redirect( "index2.php?option=$option" );
  1928. }
  1929. //$mainframe->redirect( "index2.php?option=$option", 'Form Saved, you can Open form to edit other settings now!' );
  1930. //$emailsids = JRequest::getVar( 'emailsids', array(), 'post', 'array');
  1931. if($post['formid']){
  1932. //Delet old emails and save new clean ones
  1933. $database->setQuery( "DELETE FROM #__chrono_contact_emails WHERE formid = '".$post['formid']."'" );
  1934. if (!$database->query()) {
  1935. JError::raiseWarning(100, $database->getErrorMsg());
  1936. $mainframe->redirect( "index2.php?option=$option" );
  1937. }
  1938. }
  1939. $emailslist = explode(",", $post['emailslist']);
  1940. $emailslist_clean = array();
  1941. foreach($emailslist as $emaillist){
  1942. if(trim($emaillist)){
  1943. $emailslist_clean[] = $emaillist;
  1944. }
  1945. }
  1946. preg_match_all('/start_email{.*?}end_email/i', $post['emails_temp'], $matches);
  1947. $emails = array();
  1948. $template_count = 0;
  1949. foreach ( $matches[0] as $email ) {
  1950. //echo $email;
  1951. $email = preg_replace('/start_email{/i', '', $email);
  1952. $email = preg_replace('/}end_email/i', '', $email);
  1953. $email_elements = explode('||', $email);
  1954. //$emails[] = trim($email);
  1955. $post2 = array();
  1956. $post2['to'] = str_replace('TO=[', '', str_replace(']', '', $email_elements[0]));
  1957. $post2['dto'] = str_replace('DTO=[', '', str_replace(']', '', $email_elements[1]));
  1958. $post2['subject'] = str_replace('SUBJECT=[', '', str_replace(']', '', $email_elements[2]));
  1959. $post2['dsubject'] = str_replace('DSUBJECT=[', '', str_replace(']', '', $email_elements[3]));
  1960. $post2['cc'] = str_replace('CC=[', '', str_replace(']', '', $email_elements[4]));
  1961. $post2['dcc'] = str_replace('DCC=[', '', str_replace(']', '', $email_elements[5]));
  1962. $post2['bcc'] = str_replace('BCC=[', '', str_replace(']', '', $email_elements[6]));
  1963. $post2['dbcc'] = str_replace('DBCC=[', '', str_replace(']', '', $email_elements[7]));
  1964. $post2['fromname'] = str_replace('FROMNAME=[', '', str_replace(']', '', $email_elements[8]));
  1965. $post2['dfromname'] = str_replace('DFROMNAME=[', '', str_replace(']', '', $email_elements[9]));
  1966. $post2['fromemail'] = str_replace('FROMEMAIL=[', '', str_replace(']', '', $email_elements[10]));
  1967. $post2['dfromemail'] = str_replace('DFROMEMAIL=[', '', str_replace(']', '', $email_elements[11]));
  1968. $post2['replytoname'] = str_replace('REPLYTONAME=[', '', str_replace(']', '', $email_elements[12]));
  1969. $post2['dreplytoname'] = str_replace('DREPLYTONAME=[', '', str_replace(']', '', $email_elements[13]));
  1970. $post2['replytoemail'] = str_replace('REPLYTOEMAIL=[', '', str_replace(']', '', $email_elements[14]));
  1971. $post2['dreplytoemail'] = str_replace('DREPLYTOEMAIL=[', '', str_replace(']', '', $email_elements[15]));
  1972. $post2['formid'] = $row->id;
  1973. //$post2['params'] = $post['params_email_'.$template_count];
  1974. $params = explode(",", $post['params_'.$emailslist_clean[$template_count]]);
  1975. $txt = array();
  1976. $txt[0] = "recordip=".$params[0];
  1977. $txt[1] = "emailtype=".$params[1];
  1978. $txt[2] = "enabled=".$params[2];
  1979. $txt[3] = "editor=".$params[3];
  1980. $txt[4] = "enable_attachments=".$params[4];
  1981. $post2['params'] = implode("\n", $txt);
  1982. $post2['enabled'] = $params[2];
  1983. $post2['template'] = trim($post['editor_'.$emailslist_clean[$template_count]]) ? trim($post['editor_'.$emailslist_clean[$template_count]]) : trim($emailoutput);
  1984. $template_count++;
  1985. $row2 =& JTable::getInstance('chronocontactemails', 'Table');
  1986. if (!$row2->bind( $post2 )) {
  1987. JError::raiseWarning(100, $row2->getError());
  1988. }
  1989. if (!$row2->store()) {
  1990. JError::raiseWarning(100, $row2->getError());
  1991. }
  1992. }
  1993. $mainframe->redirect( "index2.php?option=$option", 'Form Saved, you can Open form to edit other settings now!' );
  1994. //$emails = array_unique($emails);
  1995. }
  1996. function GetWizardOutput($XHTMLELEMENTS, $theme_elements, $email_template){
  1997. global $mainframe;
  1998. $database =& JFactory::getDBO();
  1999. $ClearElements = array();
  2000. $ClearElements_Email = array();
  2001. $OmittedElements = array();
  2002. foreach($XHTMLELEMENTS as $XHTMLELEMENT){
  2003. if(trim($XHTMLELEMENT)){
  2004. $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT);
  2005. $thiselement = array();
  2006. $counter = 0;
  2007. foreach($element_pieces as $element_piece){
  2008. if(($element_piece != '{')&&($element_piece != '}')&&($counter > 0)){
  2009. $linepieces = explode(" = ", $element_piece);
  2010. if(count($linepieces) == 2){
  2011. $thiselement[trim($linepieces[0])] = $linepieces[1];
  2012. }else{
  2013. $thiselement[trim($linepieces[0])] = '';
  2014. }
  2015. }
  2016. $counter++;
  2017. }
  2018. //get element tag
  2019. $element_type = '';
  2020. if (preg_match("/\[type=\".*?\"/i", $element_pieces[0], $matches)) {
  2021. $element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]);
  2022. } else {
  2023. continue;
  2024. }
  2025. //get element from theme file
  2026. $element_theme_1 = explode("<!--start_".$element_type."-->", $theme_elements);
  2027. $element_theme_2 = explode("<!--end_".$element_type."-->", $element_theme_1[1]);
  2028. if($email_template){
  2029. $element_email_1 = explode("<!--start_".$element_type."-->", $email_template);
  2030. $element_email_2 = explode("<!--end_".$element_type."-->", $element_email_1[1]);
  2031. }
  2032. //fill the element theme
  2033. foreach($thiselement as $k => $v){
  2034. $element_theme_2[0] = str_replace('{cf_'.$k.'}', $v, $element_theme_2[0]);
  2035. }
  2036. if($email_template){
  2037. foreach($thiselement as $k => $v){
  2038. $element_email_2[0] = str_replace('{cf_'.$k.'}', $v, $element_email_2[0]);
  2039. $element_email_2[0] = str_replace('{cf_cf_'.$k.'}', '{'.str_replace("[]", "", $v).'}', $element_email_2[0]);
  2040. }
  2041. }
  2042. if (preg_match("/<cf_theoptions>(.*?)<\/cf_theoptions>/is", $element_theme_2[0], $matches2)) {
  2043. //echo str_replace("<", "[", $matches2[0]);//$element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]);
  2044. $option_element = str_replace(array('<cf_theoptions>', '</cf_theoptions>') , array('', ''), $matches2[0]);
  2045. $theoptions = explode("*,*" , $thiselement['theoptions']);
  2046. $optionsdata = '';
  2047. $icounter = 0;
  2048. foreach($theoptions as $theoption){
  2049. if(trim($theoption)){
  2050. $optionsdata .= str_replace(array('{value}', '{title}', '{name}'), array($theoption, $theoption, str_replace(array('[',']'), array('', '') , $thiselement['name']).$icounter), $option_element);
  2051. $optionsdata .= CPHP_EOL;
  2052. $icounter++;
  2053. }
  2054. }
  2055. $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]);
  2056. }else if(preg_match("/<cf_thecells>(.*?)<\/cf_thecells>/is", $element_theme_2[0], $matches2)) {
  2057. $option_element = str_replace(array('<cf_thecells>', '</cf_thecells>') , array('', ''), $matches2[0]);
  2058. $theoptions = explode("*,*" , $thiselement['thecells']);
  2059. $optionsdata = '';
  2060. $icounter = 0;
  2061. foreach($theoptions as $theoption){
  2062. if(trim($theoption)){
  2063. $optionsdata .= str_replace(array('{element}'), array($ClearElements[$theoption - 1]), $option_element);
  2064. $optionsdata .= CPHP_EOL;
  2065. $OmittedElements[] = $theoption - 1;
  2066. $icounter++;
  2067. }
  2068. }
  2069. $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]);
  2070. } else{
  2071. //echo 'not found<br>';
  2072. }
  2073. //add the tooltips and label styles
  2074. if(trim($thiselement['tooltiptext'])){
  2075. $element_theme_2[0] = str_replace("{cf_tooltip}", '<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
  2076. <div class="tooltipdiv">'.trim($thiselement['tooltiptext']).'</div>', $element_theme_2[0]);
  2077. }else{
  2078. $element_theme_2[0] = str_replace("{cf_tooltip}", "", $element_theme_2[0]);
  2079. }
  2080. if(trim($thiselement['tooltiptext'])){
  2081. $cf_tooltip2 = explode(" :: ", trim($thiselement['tooltiptext']));
  2082. $element_theme_2[0] = str_replace("{cf_tooltip2}", $cf_tooltip2[1], $element_theme_2[0]);
  2083. }else{
  2084. $element_theme_2[0] = str_replace("{cf_tooltip2}", "", $element_theme_2[0]);
  2085. }
  2086. if(($element_pieces[0] == '[type="cf_button"')){
  2087. if(trim($thiselement['reset']) == '1'){
  2088. $element_theme_2[0] = str_replace("{cf_resetbutton}", '<input type="reset" name="reset" value="Reset"/>', $element_theme_2[0]);
  2089. }else{
  2090. $element_theme_2[0] = str_replace("{cf_resetbutton}", "", $element_theme_2[0]);
  2091. }
  2092. }
  2093. if(($element_pieces[0] == '[type="cf_placeholder"')){
  2094. $database->setQuery( "SELECT * FROM #__chrono_contact_elements WHERE placeholder='".$thiselement['labeltext']."' ORDER BY id" );
  2095. $placeholder = $database->loadObject();
  2096. if($placeholder){
  2097. $wizardelementparams = explode("\n", $placeholder->params);
  2098. foreach($wizardelementparams as $wizardelementparam){
  2099. if(trim($wizardelementparam)){
  2100. $paramdata = explode('=', $wizardelementparam);
  2101. $placeholder->code = str_replace("{".$paramdata[0]."}", $thiselement[$paramdata[0]], $placeholder->code);
  2102. }
  2103. }
  2104. $element_theme_2[0] = str_replace("{cf_codeplace}", $placeholder->code, $element_theme_2[0]);
  2105. }else{
  2106. $element_theme_2[0] = str_replace("{cf_codeplace}", "", $element_theme_2[0]);
  2107. }
  2108. }
  2109. if(trim($thiselement['hidelabel']) == '1'){
  2110. $element_theme_2[0] = str_replace("{cf_labeloptions}", ' style="display: none;"', $element_theme_2[0]);
  2111. }else if((trim($thiselement['labelwidth']) != 'auto')&&(trim($thiselement['labelwidth']) != '0px')){
  2112. $element_theme_2[0] = str_replace("{cf_labeloptions}", ' style="width: '.trim($thiselement['labelwidth']).';"', $element_theme_2[0]);
  2113. }else{
  2114. $element_theme_2[0] = str_replace("{cf_labeloptions}", ' style="width: 150px;"', $element_theme_2[0]);
  2115. }
  2116. if(($element_pieces[0] == '[type="cf_dropdown"')){
  2117. if((int)$thiselement['size'] > 1){
  2118. $element_theme_2[0] = str_replace("{cf_multiple}", 'multiple="multiple"', $element_theme_2[0]);
  2119. }else{
  2120. $element_theme_2[0] = str_replace("{cf_multiple}", '', $element_theme_2[0]);
  2121. }
  2122. }
  2123. if(($element_pieces[0] == '[type="cf_dropdown"')){
  2124. if($thiselement['firstoption']){
  2125. $element_theme_2[0] = str_replace("{cf_firstoptiondata}", '<option value="">'.($thiselement['firstoptiontext'] ? $thiselement['firstoptiontext'] : 'Choose Option').'</option>', $element_theme_2[0]);
  2126. }else{
  2127. $element_theme_2[0] = str_replace("{cf_firstoptiondata}", '', $element_theme_2[0]);
  2128. }
  2129. }
  2130. $ClearElements[] = $element_theme_2[0];
  2131. if($email_template){
  2132. $ClearElements_Email[] = $element_email_2[0];
  2133. }
  2134. //$htmloutput .= $element_theme_2[0];
  2135. //$emailoutput .= $element_email_2[0];
  2136. }
  2137. }
  2138. return array('theme' => $ClearElements, 'email' => $ClearElements_Email, 'omitted' => $OmittedElements);
  2139. }
  2140. function transformChronoContact( $id, $option ){
  2141. global $mainframe;
  2142. $database =& JFactory::getDBO();
  2143. $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$id."'" );
  2144. $row = $database->loadObject();
  2145. if(!trim($row->chronocode)){
  2146. $mainframe->redirect( 'index2.php?option='.$option , "Sorry but this form was not created using the wizard");
  2147. }
  2148. HTML_ChronoContact::transformChronoContact( $row, $option );
  2149. }
  2150. function previewajaxChronoContact( $option ){
  2151. global $mainframe;
  2152. $database =& JFactory::getDBO();
  2153. if(trim(JRequest::getVar('formid')) == ''){
  2154. echo 'Something went wrong, there is no form id posted!';
  2155. return;
  2156. }
  2157. $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".JRequest::getVar('formid')."'" );
  2158. $row = $database->loadObject();
  2159. if(trim(JRequest::getVar('theme')) == ''){
  2160. echo 'It looks like you didn\'t select a theme!!';
  2161. return;
  2162. }
  2163. ?>
  2164. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
  2165. <head>
  2166. <link rel="stylesheet" href="<?php echo $mainframe->getSiteURL(); ?>administrator/components/com_chronocontact/css/calendar2.css" type="text/css" />
  2167. <script type="text/javascript" src="<?php echo $mainframe->getSiteURL(); ?>media/system/js/mootools.js"></script>
  2168. <script type="text/javascript" src="<?php echo $mainframe->getSiteURL(); ?>administrator/components/com_chronocontact/js/calendar2.js"></script>
  2169. <?php
  2170. $directory = JPATH_SITE.'/administrator/components/com_chronocontact/themes/'.trim(JRequest::getVar('theme')).'/css/';
  2171. $results = array();
  2172. $handler = opendir($directory);
  2173. while ($file = readdir($handler)) {
  2174. if ( $file != '.' && $file != '..')
  2175. $results[] = $file;//str_replace(".php","", $file);
  2176. }
  2177. closedir($handler);
  2178. $counter = 0;
  2179. foreach($results as $result){
  2180. ?>
  2181. <link href="<?php echo $mainframe->getSiteURL().'administrator/components/com_chronocontact/themes/'.trim(JRequest::getVar('theme')).'/css/'.$result; ?>" rel="stylesheet" type="text/css" />
  2182. <?php
  2183. $counter++;
  2184. }
  2185. ?>
  2186. <?php
  2187. define('CPHP_EOL', "\n");
  2188. $old_chrono_code = $row->chronocode;
  2189. $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode);
  2190. $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode);
  2191. //echo $XHTMLELEMENTS[0];
  2192. $htmlcode = '';
  2193. $htmloutput = '';
  2194. //load theme
  2195. ob_start();
  2196. require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.trim(JRequest::getVar('theme')).DS."elements.php");
  2197. $theme_elements = ob_get_clean();
  2198. foreach($XHTMLELEMENTS as $XHTMLELEMENT){
  2199. if(trim($XHTMLELEMENT)){
  2200. $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT);
  2201. $thiselement = array();
  2202. $counter = 0;
  2203. foreach($element_pieces as $element_piece){
  2204. if(($element_piece != '{')&&($element_piece != '}')&&($counter > 0)){
  2205. $linepieces = explode(" = ", $element_piece);
  2206. if(count($linepieces) == 2){
  2207. $thiselement[trim($linepieces[0])] = $linepieces[1];
  2208. }else{
  2209. $thiselement[trim($linepieces[0])] = '';
  2210. }
  2211. }
  2212. $counter++;
  2213. }
  2214. if(($element_pieces[0] == '[type="cf_datetimepicker"')){
  2215. ?>
  2216. <script type="text/javascript">
  2217. window.addEvent('domready', function() {
  2218. myCal_<?php echo $thiselement['name']; ?> = new Calendar({ <?php echo $thiselement['name']; ?>: 'd/m/Y' }, { classes: ['dashboard'] });
  2219. });
  2220. </script>
  2221. <?php
  2222. }
  2223. }
  2224. }
  2225. $WizardOutput = GetWizardOutput($XHTMLELEMENTS, $theme_elements, '');
  2226. $OmittedElements = $WizardOutput['omitted'];
  2227. foreach($OmittedElements as $OmittedElement){
  2228. $WizardOutput['theme'][$OmittedElement] = '';
  2229. }
  2230. $htmloutput = implode('', $WizardOutput['theme']);
  2231. //$emailoutput = implode('', $WizardOutput['email']);
  2232. ?>
  2233. <link href="<?php echo $mainframe->getSiteURL().'components/com_chronocontact/css/'; ?>tooltip.css" rel="stylesheet" type="text/css" />
  2234. <script type="text/javascript">
  2235. Tips.implement({
  2236. initialize: function(elements, lasthope,options){
  2237. this.setOptions(options);
  2238. this.lasthope = lasthope;
  2239. this.toolTip = new Element('div', {
  2240. 'class': 'cf_'+this.options.className + '-tip',
  2241. 'id': this.options.className + '-tip-' + this.options.elementid,
  2242. 'styles': {
  2243. 'position': 'absolute',
  2244. 'top': '0',
  2245. 'left': '0',
  2246. 'visibility': 'hidden'
  2247. }
  2248. }).inject(document.body);
  2249. this.wrapper = new Element('div').inject(this.toolTip);
  2250. $$(elements).each(this.build, this);
  2251. if (this.options.initialize) this.options.initialize.call(this);
  2252. },
  2253. build: function(el){
  2254. el.$tmp.myTitle = (el.href && el.getTag() == 'a') ? el.href.replace('http://', '') : (el.rel || false);
  2255. if (el.title){
  2256. var dual = el.title.split('::');
  2257. if (dual.length > 1){
  2258. el.$tmp.myTitle = dual[0].trim();
  2259. el.$tmp.myText = dual[1].trim();
  2260. } else {
  2261. el.$tmp.myText = el.title;
  2262. }
  2263. el.removeAttribute('title');
  2264. } else {
  2265. var dual = this.lasthope.split('::');
  2266. if (dual.length > 1){
  2267. el.$tmp.myTitle = dual[0].trim();
  2268. el.$tmp.myText = dual[1].trim();
  2269. } else {
  2270. el.$tmp.myText = el.title;
  2271. }
  2272. }
  2273. if (el.$tmp.myTitle && el.$tmp.myTitle.length > this.options.maxTitleChars) el.$tmp.myTitle = el.$tmp.myTitle.substr(0, this.options.maxTitleChars - 1) + "&hellip;";
  2274. el.addEvent('mouseenter', function(event){
  2275. this.start(el);
  2276. if (!this.options.fixed) this.locate(event);
  2277. else this.position(el);
  2278. }.bind(this));
  2279. if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
  2280. var end = this.end.bind(this);
  2281. el.addEvent('mouseleave', end);
  2282. el.addEvent('trash', end);
  2283. },
  2284. start: function(el){
  2285. this.wrapper.empty();
  2286. if (el.$tmp.myTitle){
  2287. this.title = new Element('span').inject(new Element('div', {'class': 'cf_'+this.options.className + '-title'}).inject(this.wrapper)).setHTML(el.$tmp.myTitle);
  2288. }
  2289. if (el.$tmp.myText){
  2290. this.text = new Element('span').inject(new Element('div', {'class': 'cf_'+this.options.className + '-text'}).inject(this.wrapper)).setHTML(el.$tmp.myText);
  2291. }
  2292. $clear(this.timer);
  2293. this.timer = this.show.delay(this.options.showDelay, this);
  2294. }
  2295. });
  2296. window.addEvent('domready', function() {
  2297. $ES('.tooltipimg').each(function(ed){
  2298. var Tips2 = new Tips(ed, $E('div.tooltipdiv', ed.getParent().getParent()).getText(), {elementid:ed.getParent().getParent().getFirst().getNext().getProperty('id')+'_s'});
  2299. });
  2300. });
  2301. </script>
  2302. </head>
  2303. <body id="page_bg" class="color_blue bg_blue width_fmax">
  2304. <?php
  2305. echo $htmloutput;
  2306. ?>
  2307. </body>
  2308. </html>
  2309. <?php
  2310. //echo $htmlcode;
  2311. //$mainframe->close();
  2312. //return;
  2313. }
  2314. function savetransformChronoContact( $option ){
  2315. global $mainframe;
  2316. $database =& JFactory::getDBO();
  2317. if(trim(JRequest::getVar('formid')) == ''){
  2318. $mainframe->redirect( "index2.php?option=$option", 'Something went wrong, there is no form id posted!');
  2319. }
  2320. $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".JRequest::getVar('formid')."'" );
  2321. $row = $database->loadObject();
  2322. if(trim(JRequest::getVar('theme')) == ''){
  2323. $mainframe->redirect( "index2.php?option=$option", 'It looks like you didn\'t select a theme!!');
  2324. }
  2325. define('CPHP_EOL', "\n");
  2326. $old_chrono_code = $row->chronocode;
  2327. $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode);
  2328. $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode);
  2329. //echo $XHTMLELEMENTS[0];
  2330. $htmlcode = '';
  2331. $htmloutput = '';
  2332. //load theme
  2333. ob_start();
  2334. require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.trim(JRequest::getVar('theme')).DS."elements.php");
  2335. $theme_elements = ob_get_clean();
  2336. $WizardOutput = GetWizardOutput($XHTMLELEMENTS, $theme_elements, '');
  2337. $OmittedElements = $WizardOutput['omitted'];
  2338. foreach($OmittedElements as $OmittedElement){
  2339. $WizardOutput['theme'][$OmittedElement] = '';
  2340. }
  2341. $htmloutput = implode('', $WizardOutput['theme']);
  2342. //$emailoutput = implode('', $WizardOutput['email']);
  2343. $saverow =& JTable::getInstance('chronocontact', 'Table');
  2344. $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".JRequest::getVar('formid')."'" );
  2345. $post = $database->loadAssoc();
  2346. if (!$saverow->bind( $post )) {
  2347. JError::raiseWarning(100, $saverow->getError());
  2348. $mainframe->redirect( "index2.php?option=$option" );
  2349. }
  2350. $saverow->html = $htmloutput;
  2351. $saverow->theme = trim(JRequest::getVar('theme'));
  2352. //end auto transform
  2353. if (!$saverow->store()) {
  2354. JError::raiseWarning(100, $saverow->getError());
  2355. $mainframe->redirect( "index2.php?option=$option" );
  2356. }else{
  2357. $mainframe->redirect( "index2.php?option=".$option, 'Form was Successfully transformed!');
  2358. }
  2359. /*
  2360. $database->setQuery( "UPDATE #__chrono_contact SET html='".$htmloutput."', theme='".trim(JRequest::getVar('theme'))."' WHERE id='".JRequest::getVar('formid')."'");
  2361. if (!$database->query()) {
  2362. JError::raiseWarning(100, $database->getErrorMsg());
  2363. $mainframe->redirect( "index2.php?option=".$option );
  2364. }else{
  2365. $mainframe->redirect( "index2.php?option=".$option, 'Form was Successfully transformed!');
  2366. }
  2367. */
  2368. }
  2369. function wizard_elements( $option ){
  2370. global $mainframe;
  2371. $limit = JRequest::getVar('limit', $mainframe->getCfg('list_limit'));
  2372. $limitstart = JRequest::getVar('limitstart', 0);
  2373. // count entries
  2374. $database =& JFactory::getDBO();
  2375. $database->setQuery( "SELECT count(*) FROM #__chrono_contact_elements" );
  2376. $total = $database->loadResult();
  2377. echo $database->getErrorMsg();
  2378. jimport('joomla.html.pagination');
  2379. $pageNav = new JPagination($total, $limitstart, $limit);
  2380. # main database query
  2381. $database->setQuery( "SELECT * FROM #__chrono_contact_elements ORDER BY id LIMIT $pageNav->limitstart,$pageNav->limit" );
  2382. $rows = $database->loadObjectList();
  2383. if ($database->getErrorNum()) {
  2384. JError::raiseWarning(100, $database->stderr());
  2385. $mainframe->redirect( "index2.php?option=$option" );
  2386. }
  2387. HTML_ChronoContact::wizard_elements( $rows, $pageNav, $option );
  2388. }
  2389. function editElement( $id, $option ) {
  2390. $database =& JFactory::getDBO();
  2391. $row =& JTable::getInstance('chronocontactelements', 'Table');
  2392. $row->load($id);
  2393. HTML_ChronoContact::editElement( $row, $option );
  2394. }
  2395. function saveElement( $task, $option ){
  2396. global $mainframe;
  2397. $database =& JFactory::getDBO();
  2398. $row =& JTable::getInstance('chronocontactelements', 'Table');
  2399. $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
  2400. if (!$row->bind( $post )) {
  2401. JError::raiseWarning(100, $row->getError());
  2402. $mainframe->redirect( "index2.php?option=$option" );
  2403. }
  2404. $params = JRequest::getVar( 'params', array(), 'post', 'array');
  2405. if (is_array( $params )) {
  2406. $txt = array();
  2407. foreach ( $params as $k=>$v) {
  2408. $txt[] = "$k=$v";
  2409. }
  2410. $row->params = implode( "\n", $txt );
  2411. }
  2412. if (!$row->store()) {
  2413. JError::raiseWarning(100, $row->getError());
  2414. $mainframe->redirect( "index2.php?option=$option&task=tabs" );
  2415. }
  2416. if($task == 'applyelement'){
  2417. editElement( $row->id, $option );
  2418. }else{
  2419. $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" );
  2420. }
  2421. }
  2422. function cancelElement( $option ) {
  2423. global $mainframe;
  2424. $database =& JFactory::getDBO();
  2425. $row =& JTable::getInstance('chronocontactelements', 'Table');
  2426. $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" );
  2427. }
  2428. function deleteElement( $cid, $option ) {
  2429. global $mainframe;
  2430. $database =& JFactory::getDBO();
  2431. if (!is_array( $cid ) || count( $cid ) < 1) {
  2432. JError::raiseWarning(100, 'Please select an entry to delete');
  2433. $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" );
  2434. }
  2435. $cids = implode( ',', $cid );
  2436. $database->setQuery( "DELETE FROM #__chrono_contact_elements WHERE id IN ($cids)" );
  2437. if (!$database->query()) {
  2438. JError::raiseWarning(100, $database->getErrorMsg());
  2439. $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" );
  2440. }
  2441. $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" );
  2442. }
  2443. function generateAutoEmailTemplate($htmlcode){
  2444. global $mainframe;
  2445. $database =& JFactory::getDBO();
  2446. ob_start();
  2447. eval( "?>".$htmlcode);
  2448. $html_string = ob_get_clean();
  2449. $usednames = array();
  2450. //end fields names
  2451. //text fields
  2452. $pattern_input = '/<input([^>]*?)type=("|\')(text|password|hidden|file)("|\')([^>]*?)>/is';
  2453. $matches = array();
  2454. preg_match_all($pattern_input, $html_string, $matches);
  2455. foreach ( $matches[0] as $match ) {
  2456. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2457. preg_match($pattern_name, $match, $matches_name);
  2458. if (trim(str_replace('[]', '', $matches_name[2]))){
  2459. $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}";
  2460. if(!in_array($email_data_name, $usednames)){
  2461. $html_string = str_replace($match, $email_data_name, $html_string);
  2462. $usednames[] = $email_data_name;
  2463. }else{
  2464. $html_string = str_replace($match, "", $html_string);
  2465. }
  2466. }else{
  2467. $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string);
  2468. }
  2469. }
  2470. //buttons
  2471. $pattern_input = '/<input([^>]*?)type=("|\')(submit|button|reset|image)("|\')([^>]*?)>/is';
  2472. $matches = array();
  2473. preg_match_all($pattern_input, $html_string, $matches);
  2474. foreach ( $matches[0] as $match ) {
  2475. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2476. preg_match($pattern_name, $match, $matches_name);
  2477. if (trim(str_replace('[]', '', $matches_name[2]))){
  2478. $email_data_name = "";
  2479. if(!in_array($email_data_name, $usednames)){
  2480. $html_string = str_replace($match, $email_data_name, $html_string);
  2481. $usednames[] = $email_data_name;
  2482. }else{
  2483. $html_string = str_replace($match, "", $html_string);
  2484. }
  2485. }else{
  2486. $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string);
  2487. }
  2488. }
  2489. //checkboxes or radios fields
  2490. $pattern_input = '/<input([^>]*?)type=("|\')(checkbox|radio)("|\')([^>]*?)>/is';
  2491. $matches = array();
  2492. $check_radio_idslist = array();
  2493. preg_match_all($pattern_input, $html_string, $matches);
  2494. foreach ($matches[0] as $match) {
  2495. $pattern_id = '/id=("|\')([^(>|"|\')]*?)("|\')/i';
  2496. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2497. preg_match($pattern_name, $match, $matches_name);
  2498. preg_match($pattern_id, $match, $matches_id);
  2499. if (trim(str_replace('[]', '', $matches_name[2]))){
  2500. $check_radio_idslist[] = $matches_id[2];
  2501. $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}";
  2502. if(!in_array($email_data_name, $usednames)){
  2503. $html_string = str_replace($match, $email_data_name, $html_string);
  2504. $usednames[] = $email_data_name;
  2505. }else{
  2506. $html_string = str_replace($match, "", $html_string);
  2507. }
  2508. }else{
  2509. $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string);
  2510. }
  2511. }
  2512. //radios-checks labels
  2513. $pattern_label = '/<label([^>]*?)for=("|\')('.implode("|", $check_radio_idslist).')("|\')([^>]*?)>(.*?)<\/label>/is';
  2514. $matches = array();
  2515. preg_match_all($pattern_label, $html_string, $matches);
  2516. foreach ( $matches[0] as $match ) {
  2517. $html_string = str_replace($match, "", $html_string);
  2518. }
  2519. //textarea fields
  2520. $pattern_textarea = '/<textarea([^>]*?)>(.*?)<\/textarea>/is';
  2521. $matches = array();
  2522. preg_match_all($pattern_textarea, $html_string, $matches);
  2523. $namematch = '';
  2524. foreach ( $matches[0] as $match ) {
  2525. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2526. preg_match($pattern_name, $match, $matches_name);
  2527. if (trim(str_replace('[]', '', $matches_name[2]))){
  2528. $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}";
  2529. if(!in_array($email_data_name, $usednames)){
  2530. $html_string = str_replace($match, $email_data_name, $html_string);
  2531. $usednames[] = $email_data_name;
  2532. }else{
  2533. $html_string = str_replace($match, "", $html_string);
  2534. }
  2535. }else{
  2536. $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string);
  2537. }
  2538. }
  2539. //select boxes
  2540. $pattern_select = '/<select(.*?)select>/is';
  2541. $matches = array();
  2542. preg_match_all($pattern_select, $html_string, $matches);
  2543. foreach ($matches[0] as $match) {
  2544. $selectmatch = $match;
  2545. $pattern_select2 = '/<select([^>]*?)>/is';
  2546. preg_match_all($pattern_select2, $match, $matches2);
  2547. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2548. preg_match($pattern_name, $matches2[0][0], $matches_name);
  2549. if (trim(str_replace('[]', '', $matches_name[2]))){
  2550. $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}";
  2551. if(!in_array($email_data_name, $usednames)){
  2552. $html_string = str_replace($match, $email_data_name, $html_string);
  2553. $usednames[] = $email_data_name;
  2554. }else{
  2555. $html_string = str_replace($match, "", $html_string);
  2556. }
  2557. }else{
  2558. $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string);
  2559. }
  2560. }
  2561. return $html_string;
  2562. }
  2563. function generateFieldsNamesTypes($htmlcode){
  2564. global $mainframe;
  2565. $database =& JFactory::getDBO();
  2566. ob_start();
  2567. eval( "?>".$htmlcode);
  2568. $html_string = ob_get_clean();
  2569. $fieldsnames = array();
  2570. $fieldstypes = array();
  2571. //text fields
  2572. $pattern_input = '/<input([^>]*?)type=("|\')(text|password|hidden|file|checkbox|radio)("|\')([^>]*?)>/is';
  2573. $matches = array();
  2574. preg_match_all($pattern_input, $html_string, $matches);
  2575. foreach ( $matches[0] as $match ) {
  2576. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2577. $pattern_type = '/type=("|\')([^(>|"|\')]*?)("|\')/i';
  2578. preg_match($pattern_name, $match, $matches_name);
  2579. preg_match($pattern_type, $match, $matches_type);
  2580. if (trim(str_replace('[]', '', $matches_name[2])) && !in_array(trim(str_replace('[]', '', $matches_name[2])), $fieldsnames)){
  2581. $fieldsnames[] = str_replace('[]', '', $matches_name[2]);
  2582. if ($matches_type[2]){
  2583. $fieldstypes[] = $matches_type[2];
  2584. }
  2585. }
  2586. }
  2587. //textarea fields
  2588. $pattern_textarea = '/<textarea([^>]*?)>(.*?)<\/textarea>/is';
  2589. $matches = array();
  2590. preg_match_all($pattern_textarea, $html_string, $matches);
  2591. foreach ( $matches[0] as $match ) {
  2592. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2593. preg_match($pattern_name, $match, $matches_name);
  2594. if (trim(str_replace('[]', '', $matches_name[2])) && !in_array(trim(str_replace('[]', '', $matches_name[2])), $fieldsnames)){
  2595. $fieldsnames[] = str_replace('[]', '', $matches_name[2]);
  2596. $fieldstypes[] = "textarea";
  2597. }
  2598. }
  2599. //select boxes
  2600. $pattern_select = '/<select(.*?)select>/is';
  2601. $matches = array();
  2602. preg_match_all($pattern_select, $html_string, $matches);
  2603. foreach ($matches[0] as $match) {
  2604. $selectmatch = $match;
  2605. $pattern_select2 = '/<select([^>]*?)>/is';
  2606. preg_match_all($pattern_select2, $match, $matches2);
  2607. $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i';
  2608. preg_match($pattern_name, $matches2[0][0], $matches_name);
  2609. if (trim(str_replace('[]', '', $matches_name[2])) && !in_array(trim(str_replace('[]', '', $matches_name[2])), $fieldsnames)){
  2610. $fieldsnames[] = str_replace('[]', '', $matches_name[2]);
  2611. $fieldstypes[] = "select";
  2612. }
  2613. }
  2614. return array("names" => $fieldsnames, "types" => $fieldstypes);
  2615. }
  2616. ?>