PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 1ms 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

Large files files are truncated, but you can click here to view the full file

  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 "<fon…

Large files files are truncated, but you can click here to view the full file