/src/site/administrator/components/com_chronocontact/admin.chronocontact.php
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
- <?php
- /*
- /**
- * CHRONOFORMS version 3.0
- * Copyright (c) 2008 Chrono_Man, ChronoEngine.com. All rights reserved.
- * Author: Chrono_Man (ChronoEngine.com)
- * See readme.html.
- * @license GNU/GPL
- * Visit http://www.ChronoEngine.com for regular update and information.
- **/
- /* ensure that this file is not called from another file */
- defined('_JEXEC') or die('Restricted access');
- //global $mosConfig_lang, $mosConfig_absolute_path, $chronocontact_params;
- // Loading of the database class and the HTML class
- require_once( JApplicationHelper::getPath( 'admin_html' ) );
- require_once( JApplicationHelper::getPath( 'class' ) );
- $id = JRequest::getVar( 'id', '', 'get', 'int', 0 );
- //$task = JRequest::getVar( 'task', '', 'post', 'string', '' );
- $cid = JRequest::getVar( 'cid', array(), 'post', 'array');
- if (!is_array( $cid )) {
- $cid = array(0);
- }
- $cid_del = JRequest::getVar( 'cid_del', array(), 'post', 'array');
- if (!is_array( $cid_del )) {
- $cid_del = array(0);
- }
- ?>
- <?php echo JHTML::_('behavior.tooltip'); ?>
- <?php
- // case differentiation
- switch ($task) {
- case "ajax":
- ajaxfields();
- break;
- case "adminview":
- showadminformChronoContact( '', $cid[0], $option );
- break;
- case "submitadminform":
- submitadminformChronoContact( $option );
- break;
- case "editdata":
- showadminformChronoContact( $cid[0], '', $option );
- break;
- case "transform":
- transformChronoContact( $cid[0], $option );
- break;
- case "savetransform":
- savetransformChronoContact( $option );
- break;
- case "previewajax":
- previewajaxChronoContact( $option );
- break;
- case 'doupgrade':
- doupgrade($option);
- break;
- case 'validatelicense':
- validatelicense($option);
- break;
- case 'validatelicenseframe':
- validatelicenseframe($option);
- break;
- case 'validatelicensedata':
- validatelicensedata();
- break;
- /////////////////////
- case "publish":
- publishChronoContact( $cid, 1, $option );
- break;
- case "unpublish":
- publishChronoContact( $cid, 0, $option );
- break;
- case "add":
- editChronoContact( 0, $option );
- break;
- case "edit":
- editChronoContact( $cid[0], $option );
- break;
- case "applychanges":
- saveChronoContact( $option, $task );
- //editChronoContact( $_POST['id'], $option );
- break;
- case "remove":
- removeChronoContact( $cid, $option );
- break;
- case "save":
- saveChronoContact( $option, $task );
- break;
- case "copy":
- copyChronoContact( $cid[0], $option );
- break;
- case "cancel":
- cancelChronoContact( $option );
- break;
- case "addmenuitem":
- addmenuitem( $option );
- break;
- ////////
- case "cancelview":
- showdataChronoContact( 0, $option );
- break;
- case "show":
- $showid = (count($cid) == 0) ? 0 : $cid[0];
- showdataChronoContact( $showid, $option );
- break;
- case "viewdata":
- viewdataChronoContact( $cid[0], $option );
- break;
- case "createtable":
- maketableChronoContact( $cid[0], $option );
- break;
- case "edittable":
- maketableChronoContact( 0, $option );
- break;
- case "tablemanager":
- tablemanagerChronoContact( $option );
- break;
- case "updatetablelist":
- updatetablelistChronoContact( $option );
- break;
- case "deletetable":
- deletetableChronoContact( $cid[0], $option);
- break;
- case "finalizetable":
- finalizetableChronoContact( $option );
- break;
- case "deleterecord":
- deleterecordChronoContact( $cid, $option );
- break;
- ////// backup
- case "backup":
- case "backupall":
- backupChronoContact( $cid[0], $option, $task );
- break;
- case "restore1":
- restore1ChronoContact( 0, $option );
- break;
- case "restore2":
- restore2ChronoContact( 0, $option );
- break;
- case "backexcel":
- BackupExcel( $id, $option );
- break;
- case "backcsv":
- BackupCSV( $id, $option );
- break;
- ////// config
- case 'config':
- showConfig( $option );
- break;
- case 'saveconfig':
- saveSettings( $option );
- break;
- case 'cancelconfig':
- cancelSettings( $option );
- break;
- case 'save_conf':
- save_conf( $option );
- break;
- ////// wizard
- case 'form_wizard':
- form_wizard( '', $option );
- break;
- case 'wizardedit':
- form_wizard( $cid[0], $option );
- break;
- case 'wizard_elements':
- wizard_elements( $option );
- break;
- case 'save_form_wizard':
- save_form_wizard( $option );
- break;
- case 'editelement':
- editElement( $cid[0], $option );
- break;
- case 'newelement':
- editElement( 0, $option );
- break;
- case 'saveelement':
- case 'applyelement':
- saveElement( $task, $option );
- break;
- case 'cancelelement':
- cancelElement( $option );
- break;
- case 'deleteelement':
- deleteElement( $cid, $option );
- break;
- ///// menu tools
- case 'menu_creator':
- menu_creator( $option );
- break;
- case 'menu_remover':
- menu_remover( $option );
- break;
- case 'menu_save':
- menu_save( $option );
- break;
- case 'menu_delete':
- menu_delete( $cid, $option );
- break;
- ///////////////
- default:
- global $mainframe;
- $database =& JFactory::getDBO();
- $switch = 1;
- if(strpos("x".$task,"plugin_")){
- $directory = JPATH_SITE.'/components/com_chronocontact/plugins/';
- $results = array();
- $handler = opendir($directory);
- while ($file = readdir($handler)) {
- if ( $file != '.' && $file != '..' && substr($file, -4) == '.php' && substr($file, 0, 3) == 'cf_')
- $results[] = str_replace(".php","", $file);
- }
- closedir($handler);
- foreach($results as $result){
- if($task == 'plugin_'.$result){
- require_once(JPATH_SITE."/components/com_chronocontact/plugins/".$result.".php");
- ${$result} = new $result();
- $switch = 0;
-
- $database->setQuery( "SELECT id FROM #__chrono_contact_plugins WHERE form_id='".$cid[0]."' AND name='".$result."'" );
- $id = $database->loadResult();
- $row =& JTable::getInstance('chronocontactplugins', 'Table');
- $row->load( $id );
- ${$result}->show_conf($row, $id, $cid[0], $option);
- break;
- }
- }
- }
- //echo 'xxx'.$cf_joomla_registration->result_TITLE;
- if($switch == 1){
- showChronoContact( $option );
- }
- break;
- }
- function save_conf( $option ){
- $plugin = JRequest::getVar('name');
- require_once(JPATH_SITE."/components/com_chronocontact/plugins/".$plugin.".php");
- ${$plugin} = new $plugin();
- ${$plugin}->save_conf($option);
- }
- function ajaxfields(){
- global $mainframe;
- $database =& JFactory::getDBO();
- $plugin = JRequest::getVar('plugin');
- $method = JRequest::getVar('method');
- require_once(JPATH_SITE."/components".DS."com_chronocontact".DS."plugins".DS.$plugin.".php");
- ${$plugin} = new $plugin();
- ${$plugin}->{$method}();
- }
- function doupgrade($option){
- global $mainframe;
- $database =& JFactory::getDBO();
- $sql = "ALTER TABLE #__chrono_contact ADD `extravalrules` LONGTEXT NOT NULL AFTER `titlesall`";
- $database->setQuery($sql);
- if (!$database->query()) {
- echo $database->getErrorMsg();
- }
- $sql = "ALTER TABLE #__chrono_contact ADD `stylecode` LONGTEXT NOT NULL AFTER `scriptcode`";
- $database->setQuery($sql);
- if (!$database->query()) {
- echo $database->getErrorMsg();
- }
- $sql = "ALTER TABLE #__chrono_contact ADD `chronocode` LONGTEXT NOT NULL AFTER `autogenerated`";
- $database->setQuery($sql);
- if (!$database->query()) {
- echo $database->getErrorMsg();
- }
- $sql = "ALTER TABLE #__chrono_contact ADD `theme` TEXT NOT NULL AFTER `chronocode`";
- $database->setQuery($sql);
- if (!$database->query()) {
- echo $database->getErrorMsg();
- }
- $sql = "ALTER TABLE #__chrono_contact_emails
- ADD COLUMN `replytoname` TEXT AFTER `dfromemail`,
- ADD COLUMN `dreplytoname` TEXT AFTER `replytoname`,
- ADD COLUMN `replytoemail` TEXT AFTER `dreplytoname`,
- ADD COLUMN `dreplytoemail` TEXT AFTER `replytoemail`;";
- $database->setQuery($sql);
- if (!$database->query()) {
- echo $database->getErrorMsg();
- }
- $sql = "ALTER TABLE #__chrono_contact_elements
- ADD COLUMN `title` VARCHAR(255) AFTER `id`,
- ADD COLUMN `params` LONGTEXT AFTER `code`;";
- $database->setQuery($sql);
- if (!$database->query()) {
- echo $database->getErrorMsg();
- }
-
- // Load Demo form
- $option = 'com_chronocontact';
- $filename = 'basicDemo.cfbak';
- $path = JPATH_SITE.DS.'components'.DS.'com_chronocontact'.DS.'uploads';
- $data = file_get_contents( $path.DS.$filename );
- $data = str_replace( '&', '&', $data );
- $values = '(';
- $values2 = '(';
-
- preg_match_all('/\<++(.*?)\<endendend>/s', $data, $matches);
- $i = 0;
- foreach ( $matches[0] as $match ) {
- if($i != 0){
- $values .= ',';
- $values2 .= ',';
- }
- preg_match_all('/\<++(.*?)\++>/s', $match, $match2es);
- $fieldvalue = str_replace($match2es[0][0],'',$match);
- $match2es[0][0] = str_replace('<++-++-++','',$match2es[0][0]);
- $match2es[0][0] = str_replace('++-++-++>','',$match2es[0][0]);
- $values .= $match2es[0][0];
- if($i == 0){
- $values2 .= "''";
- }else{
- $match = str_replace('<++-++-++'.$match2es[0][0].'++-++-++>','',$match);
- $match = str_replace('<endendend>','',$match);
- $match = trim($match," \t.");
- $values2 .= "'".addslashes($match)."'";
- }
- $i++;
- }
- $values .= ')';
- $values2 .= ')';
- $database->setQuery( "INSERT INTO #__chrono_contact ".$values." VALUES ".$values2 );
- if (!$database->query()) {
- JError::raiseWarning(100, "Restoring the whole form failed Failed, error : ".$database->getErrorMsg());
- //$mainframe->redirect( "index2.php?option=$option" );
- }else{
- //$mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
- }
- $lastformid = $database->insertid();
-
- // Restore Emails
- $values = '(`';
- $values2 = '(';
- $emails_data = array();
- $emails_count = explode('<cf_email_separator>', $data);
- $fields_count_1 = explode('{cfbak_start_emails}', $emails_count[0]);
- $fields_count_2 = explode('<endendend2>', $fields_count_1[1]);
- preg_match_all('/\<2++(.*?)\<endendend2>/s', $data, $matches);
- $i = 0;
- $i_v = 0;
- $counter = 0;
- foreach ( $matches[0] as $match ) {
- preg_match_all('/\<2++(.*?)\++>/s', $match, $match2es);
- $fieldvalue = str_replace($match2es[0][0],'',$match);
- $match2es[0][0] = str_replace('<2++-++-++','',$match2es[0][0]);
- $match2es[0][0] = str_replace('++-++-++>','',$match2es[0][0]);
- if($i_v < (count($fields_count_2) - 1)){
- if($i_v != 0){$values .= '`,`';}
- $values .= $match2es[0][0];
- }
- if($i != 0){$values2 .= ',';}
- if($i == 0){
- $values2 .= "''";
- }else if($i == 1){
- $values2 .= "'".$lastformid."'";
- }else{
- $match = str_replace('<2++-++-++'.$match2es[0][0].'++-++-++>','',$match);
- $match = str_replace('<endendend2>','',$match);
- $match = trim($match," \t.");
- $values2 .= "'".addslashes($match)."'";
- }
- $counter++;
- $i++;
- $i_v++;
-
- if($counter == (count($fields_count_2) - 1)){
- $values2 .= ')';
- $emails_data[] = $values2;
- $values2 = '(';
- $counter = 0;
- $i = 0;
- }
- }
- $values .= '`)';
- foreach($emails_data as $email_data){
- $database->setQuery( "INSERT INTO #__chrono_contact_emails ".$values." VALUES ".$email_data );
- if (!$database->query()) {
- JError::raiseWarning(100, "Restoring Emails Setup Failed, error : ".$database->getErrorMsg());
- //$mainframe->redirect( "index2.php?option=$option" );
- }else{
- //$mainframe->redirect( 'index2.php?option='.$option , "Restored successfully");
- }
- }
- //$mainframe->redirect( 'index2.php?option='.$option , "Demo form loaded successfully");
-
- $mainframe->redirect( "index2.php?option=$option", 'Upgrade went successfully' );
- }
- function validatelicense($option){
- HTML_ChronoContact::validatelicensepage( $option );
- }
- function validatelicenseframe($option){
- //HTML_ChronoContact::validatelicenseframe( $option );
- }
- function validatelicensedata(){
- global $mainframe;
- preg_match('/http(s)*:\/\/(.*?)\//i', $mainframe->getSiteURL(), $matches);
- $database =& JFactory::getDBO();
- $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
- $database->setQuery( $query );
- $result = $database->loadObject();
- //$configs = JComponentHelper::getParams('com_chronocontact');
- $configs = new JParameter($result->params);
- $postfields = array();
- $postfields['license_key'] = $configs->get('licensecode', '');
- $postfields['domain_name'] = $matches[2];
- $postfields['pid'] = $_POST['pid'];
- $validstatus = false;
- if(function_exists('fsockopen')){
- $validstatus = validationconnect('http', 'www.chronoengine.com', $port='80', $path='/index2.php?option=com_chronocontact&task=extra&chronoformname=validateLicense', $postfields);
- }
-
- if((!$validstatus)||($validstatus == 'error')||!function_exists('fsockopen')){
- if (!function_exists('curl_init')){
- $validstatus = false;
- }else{
- $fields = '';
- $ch = curl_init();
- //$postfields = array();
- foreach( $postfields as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";
- curl_setopt($ch, CURLOPT_URL, 'http://www.chronoengine.com/index2.php?option=com_chronocontact&task=extra&chronoformname=validateLicense');
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " ));
- if($configs->get('curlproxy', '')){
- curl_setopt($ch, CURLOPT_PROXY, $configs->get('curlproxy'));
- }
- $output = curl_exec($ch);
- curl_close($ch);
- $validstatus = $output;
- }
- }
- //return $validstatus;
- if($validstatus == 'valid'){
- if($configs->get('licensecode', '')){
- //if(!$configs->get('licensevalid', '')){
- $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
- $database->setQuery( $query );
- $result = $database->loadObject();
- $newline = "\n";
- if($result){
- $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=1';
- $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=com_chronocontact" );
- }
- }
- //}
- }
- $mainframe->redirect( "index2.php?option=com_chronocontact", 'Your Install was validated successfully' );
- }else if($validstatus == 'invalid'){
- $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
- $database->setQuery( $query );
- $result = $database->loadObject();
- $newline = "\n";
- if($result){
- $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=0';
- $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=com_chronocontact" );
- }
- }
- $mainframe->redirect( "index2.php?option=com_chronocontact", 'We couldn\'t validate your key because of some wrong data used' );
- }else{
- if(trim(JRequest::getVar('instantcode'))){
- $step1 = base64_decode(trim(JRequest::getVar('instantcode')));
- $step2 = str_replace(substr(md5(str_replace('www.', '', strtolower($matches[2]))), 0, 7), '', $step1);
- $step3 = str_replace(substr(md5(str_replace('www.', '', strtolower($matches[2]))), - strlen(md5(str_replace('www.', '', strtolower($matches[2])))) + 7), '', $step2);
- $step4 = str_replace(substr($configs->get('licensecode', ''), 0, 10), '', $step3);
- $step5 = str_replace(substr($configs->get('licensecode', ''), - strlen($configs->get('licensecode', '')) + 10), '', $step4);
- //echo (int)$step5;return;
- //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')))){
- if(((int)$step5 < (strtotime("now") + (24 * 60 * 60)))&&((int)$step5 > (strtotime("now") - (24 * 60 * 60)))){
- $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
- $database->setQuery( $query );
- $result = $database->loadObject();
- $newline = "\n";
- if($result){
- $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=1';
- $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=com_chronocontact" );
- }
- }
- $mainframe->redirect( "index2.php?option=com_chronocontact", 'Your key was validated successfully' );
- }else{
- $mainframe->redirect( "index2.php?option=com_chronocontact", 'Invalid instant code' );
- }
- }else{
- $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
- $database->setQuery( $query );
- $result = $database->loadObject();
- $newline = "\n";
- if($result){
- $newparams = 'showtipoftheday='.$configs->get('showtipoftheday', 1).$newline.'licensecode='.$configs->get('licensecode', '').$newline.'licensevalid=0';
- $database->setQuery( "UPDATE `#__components` SET params='".$newparams."' WHERE id='".$result->id."'");
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=com_chronocontact" );
- }
- }
- $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' );
- }
- }
- }
- function validationconnect($type, $host, $port='80', $path='/', $data=array()) {
- global $mainframe;
- $_err = 'lib sockets::'.__FUNCTION__.'(): ';
- $str = '';
- $d = array();
- switch($type) { case 'http': $type = ''; case 'ssl': continue; default: die($_err.'bad $type'); }
-
- if(!empty($data)){
- foreach($data as $k => $v){
- $strarr[] = urlencode($k).'='.urlencode($v);
- }
- }
- $str = implode('&', $strarr);
- $result = '';
- //echo $str;
- $fp = fsockopen($host, $port, $errno, $errstr, 30);
- if(!$fp){
- //$mainframe->redirect( "index2.php?option=com_chronocontact", $_err.$errstr.$errno);
- $result = 'error';
- //die($_err.$errstr.$errno);
- }else{
- fputs($fp, "POST $path HTTP/1.1\r\n");
- fputs($fp, "Host: $host\r\n");
- fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
- fputs($fp, "Content-length: ".strlen($str)."\r\n");
- fputs($fp, "Connection: close\r\n\r\n");
- fputs($fp, $str."\r\n\r\n");
-
- while(!feof($fp)){
- $d[] = fgets($fp,4096);
- }
- fclose($fp);
- $result = $d[count($d) - 1];
- } return $result;
- }
- // Publishing of the entries
- function publishChronoContact( $cid, $publish, $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- if (count( $cid ) < 1) {
- $action = $publish ? 'publish' : 'unpublish';
- JError::raiseWarning(100, 'Select a item to '.$action);
- $mainframe->redirect( "index2.php?option=$option" );
- }
- $cids = implode( ',', $cid );
- $database->setQuery( "UPDATE #__chrono_contact SET published=".$publish." WHERE id IN ($cids)");
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- if (count( $cid ) == 1) {
- $row =& JTable::getInstance('chronocontact', 'Table');
- $row->checkin( $cid[0] );
- }
- $mainframe->redirect( "index2.php?option=$option" );
- }
- function editChronoContact( $id, $option ) {
- $database =& JFactory::getDBO();
- $row =& JTable::getInstance('chronocontact', 'Table');
- $row->load($id);
- HTML_ChronoContact::editChronoContact( $row, $option );
- }
- // deletion of entries
- function removeChronoContact( $cid, $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- if (!is_array( $cid ) || count( $cid ) < 1) {
- JError::raiseWarning(100, 'Please select an entry to delete');
- $mainframe->redirect( "index2.php?option=$option" );
- }
- $cids = implode( ',', $cid );
- $database->setQuery( "DELETE FROM #__chrono_contact WHERE id IN ($cids)" );
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- $database->setQuery( "DELETE FROM #__chrono_contact_emails WHERE formid IN ($cids)" );
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- $mainframe->redirect( "index2.php?option=$option" );
- }
- function copyChronoContact( $id , $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- $row =& JTable::getInstance('chronocontact', 'Table');
- $row->load($id);
- $row->id = '';
- if (!$row->store()) {
- JError::raiseWarning(100, $row->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- //copy emails
- $database->setQuery( "SELECT * FROM #__chrono_contact_emails WHERE formid='".$id."'" );
- $emails = $database->loadAssocList();
- //print_r($emails);
- foreach($emails as $email){
- $email['emailid'] = '';
- $email['formid'] = $row->id;
- $row2 =& JTable::getInstance('chronocontactemails', 'Table');
- if (!$row2->bind( $email )) {
- JError::raiseWarning(100, $row2->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- if (!$row2->store()) {
- JError::raiseWarning(100, $row2->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- }
- //copy plugins
- $database->setQuery( "SELECT * FROM #__chrono_contact_plugins WHERE form_id='".$id."'" );
- $plugins = $database->loadAssocList();
- //print_r($emails);
- foreach($plugins as $plugin){
- $plugin['id'] = '';
- $plugin['form_id'] = $row->id;
- $row3 =& JTable::getInstance('chronocontactplugins', 'Table');
- if (!$row3->bind( $plugin )) {
- JError::raiseWarning(100, $row3->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- if (!$row3->store()) {
- JError::raiseWarning(100, $row3->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- }
- $mainframe->redirect( "index2.php?option=".$option );
- }
- // save entry
- function saveChronoContact( $option, $task ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- $row =& JTable::getInstance('chronocontact', 'Table');
- $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
- //$post = JRequest::getVar( 'description', '', 'post','string', _J_ALLOWRAW );
- if (!$row->bind( $post )) {
- JError::raiseWarning(100, $row->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
-
- $params = JRequest::getVar( 'params', array(), 'post', 'array');
- if (is_array( $params )) {
- $txt = array();
- foreach ( $params as $k=>$v) {
- $txt[] = "$k=$v";
- }
-
- $plugins = JRequest::getVar( 'plugins', array(), 'post', 'array');
- $mplugins_order = JRequest::getVar( 'mplugins_order', array(), 'post', 'array');
- $plugins_enable = JRequest::getVar( 'plugins_enable', array(), 'post', 'array');
- $pluginslist = array();
- $mplugins_orderlist = array();
- foreach($plugins_enable as $k => $plugin_enable){
- if($plugin_enable == 1){
- $pluginslist[] = $plugins[$k];
- $mplugins_orderlist[] = $mplugins_order[$k];
- }
- }
- if(is_array( $plugins )){
- $txt[] = "plugins=".implode(",", $pluginslist);
- }
- if(is_array( $mplugins_order )){
- $txt[] = "mplugins_order=".implode(",", $mplugins_orderlist);
- }
- $tablenames = JRequest::getVar( 'tablenames', array(), 'post', 'array');
- if(is_array( $tablenames )){
- $txt[] = "tablenames=".implode(",",$tablenames);
- }
- $row->paramsall = implode( "\n", $txt );
- }
-
- $FieldsNamesTypes = generateFieldsNamesTypes($post["html"]);
- $row->fieldsnames = implode(",", $FieldsNamesTypes["names"]);
- $row->fieldstypes = implode(",", $FieldsNamesTypes["types"]);
-
-
- $row->dbclasses = "";
- if (is_array( $params )) {
- foreach($tablenames as $tablename){
- //Create Class
- $tables = array();
- $tables[] = $tablename;
- $result = $database->getTableFields( $tables, false );
- //print_r($result[$row->tablenames]);
- $table_fields = $result[$tablename];
- $row->dbclasses .= "<?php";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "if (!class_exists('Table".str_replace($mainframe->getCfg('dbprefix'), '', $tablename)."')) {";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "class Table".str_replace($mainframe->getCfg('dbprefix'), '', $tablename)." extends JTable {";
- $primary = 'id';
- foreach($table_fields as $table_field => $field_data){
- $row->dbclasses .= "\n";
- $row->dbclasses .= "var \$".$table_field." = null;";
- if($field_data->Key == 'PRI')$primary = $table_field;
- }
- $row->dbclasses .= "\n";
- $row->dbclasses .= "function __construct( &\$database ) {";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "parent::__construct( '".$tablename."', '".$primary."', \$database );";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "}";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "}";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "}";
- $row->dbclasses .= "\n";
- $row->dbclasses .= "?>";
- $row->dbclasses .= "\n";
- }
- }
- $row->autogenerated = "";
-
- //$tables = explode("," , $paramsvalues->tablenames);
- foreach($tablenames as $tablename){
- $row->autogenerated = $row->autogenerated.'<?php
- $MyForm =& CFChronoForm::getInstance("'.$post['name'].'");
- if($MyForm->formparams("dbconnection") == "Yes"){
- $user = JFactory::getUser();
- $row =& JTable::getInstance("'.str_replace($mainframe->getCfg("dbprefix"), "", $tablename).'", "Table");
- srand((double)microtime()*10000);
- $inum = "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
- JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
- JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
- JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
- JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
- $post = JRequest::get( "post" , JREQUEST_ALLOWRAW );
- if (!$row->bind( $post )) {
- JError::raiseWarning(100, $row->getError());
- }
- if (!$row->store()) {
- JError::raiseWarning(100, $row->getError());
- }
- $MyForm->tablerow["'.$tablename.'"] = $row;
- }
- ?>
- ';
- }
-
-
- if (!$row->store()) {
- JError::raiseWarning(100, $row->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
-
- //Emails
- //Delet old emails and save new clean ones
- $database->setQuery( "DELETE FROM #__chrono_contact_emails WHERE formid = '".$row->id."'" );
- if (!$database->query()) {
- JError::raiseWarning(100, $database->getErrorMsg());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- preg_match_all('/start_email{.*?}end_email/i', $post['emails_temp'], $matches);
- $emails = array();
- $template_count2 = 0;
- $emails_ids = explode(',', str_replace('email_', '', $post['emails_temp_ids']));
- foreach ( $matches[0] as $email ) {
- $template_count = $emails_ids[$template_count2+1];
- //echo $email;return;
- $email = preg_replace('/start_email{/i', '', $email);
- $email = preg_replace('/}end_email/i', '', $email);
- $email_elements = explode('||', $email);
- //$emails[] = trim($email);
- $post2 = array();
- //$post2['emailid'] = ;
- $post2['to'] = str_replace('TO=[', '', str_replace(']', '', $email_elements[0]));
- $post2['dto'] = str_replace('DTO=[', '', str_replace(']', '', $email_elements[1]));
- $post2['subject'] = str_replace('SUBJECT=[', '', str_replace(']', '', $email_elements[2]));
- $post2['dsubject'] = str_replace('DSUBJECT=[', '', str_replace(']', '', $email_elements[3]));
- $post2['cc'] = str_replace('CC=[', '', str_replace(']', '', $email_elements[4]));
- $post2['dcc'] = str_replace('DCC=[', '', str_replace(']', '', $email_elements[5]));
- $post2['bcc'] = str_replace('BCC=[', '', str_replace(']', '', $email_elements[6]));
- $post2['dbcc'] = str_replace('DBCC=[', '', str_replace(']', '', $email_elements[7]));
- $post2['fromname'] = str_replace('FROMNAME=[', '', str_replace(']', '', $email_elements[8]));
- $post2['dfromname'] = str_replace('DFROMNAME=[', '', str_replace(']', '', $email_elements[9]));
- $post2['fromemail'] = str_replace('FROMEMAIL=[', '', str_replace(']', '', $email_elements[10]));
- $post2['dfromemail'] = str_replace('DFROMEMAIL=[', '', str_replace(']', '', $email_elements[11]));
- $post2['replytoname'] = str_replace('REPLYTONAME=[', '', str_replace(']', '', $email_elements[12]));
- $post2['dreplytoname'] = str_replace('DREPLYTONAME=[', '', str_replace(']', '', $email_elements[13]));
- $post2['replytoemail'] = str_replace('REPLYTOEMAIL=[', '', str_replace(']', '', $email_elements[14]));
- $post2['dreplytoemail'] = str_replace('DREPLYTOEMAIL=[', '', str_replace(']', '', $email_elements[15]));
- $post2['formid'] = $row->id;
-
- //$post2['params'] = $post['params_email_'.$template_count];
- $params = explode(",", $post['params_email_'.$template_count]);
- $txt = array();
- $txt[0] = "recordip=".$params[0];
- $txt[1] = "emailtype=".$params[1];
- $txt[2] = "enabled=".$params[2];
- $txt[3] = "editor=".$params[3];
- $txt[4] = "enable_attachments=".$params[4];
- $post2['params'] = implode("\n", $txt);
- $post2['template'] = trim($post['editor_email_'.$template_count]) ? trim($post['editor_email_'.$template_count]) : generateAutoEmailTemplate($post['html']);
- $template_count2++;
- $post2['enabled'] = $params[2];
-
- $row2 =& JTable::getInstance('chronocontactemails', 'Table');
- if (!$row2->bind( $post2 )) {
- JError::raiseWarning(100, $row2->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- if (!$row2->store()) {
- JError::raiseWarning(100, $row2->getError());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- }
-
- //end Emails
- if($task != 'applychanges'){
- $mainframe->redirect( "index2.php?option=".$option );
- }else{
- editChronoContact( $row->id, $option );
- }
- }
- // abort the current action
- function cancelChronoContact( $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- //$row =& JTable::getInstance('chronocontact', 'Table');
- //$row->bind( $_POST );
- //$row->checkin();
- $mainframe->redirect( "index2.php?option=$option" );
- }
- // list entries
- function showChronoContact($option) {
- global $mainframe;
- $limit = $mainframe->getUserStateFromRequest($option.'.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
- $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart', 'limitstart', 0, 'int');
- // count entries
- $database =& JFactory::getDBO();
- $database->setQuery( "SELECT count(*) FROM #__chrono_contact" );
- $total = $database->loadResult();
- echo $database->getErrorMsg();
- jimport('joomla.html.pagination');
- $pageNav = new JPagination($total, $limitstart, $limit);
- # main database query
- $database->setQuery( "SELECT * FROM #__chrono_contact ORDER BY id LIMIT $pageNav->limitstart,$pageNav->limit" );
- $rows = $database->loadObjectList();
- if ($database->getErrorNum()) {
- JError::raiseWarning(100, $database->stderr());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- HTML_ChronoContact::showChronoContact( $rows, $pageNav, $option );
- }
- ///////////////////////////////
- function showdataChronoContact($id, $option) {
- global $mainframe;
- $database =& JFactory::getDBO();
-
- if(!$id){
- if(is_array(JRequest::getVar('formid', array(0), 'post', 'array'))){
- $id_arr = JRequest::getVar('formid', array(0), 'post', 'array');
- $id = $id_arr[0];
- }else{
- $id = JRequest::getVar('formid', 0, 'post', 'int');
- }
- }
- if(!$id){
- $id = JRequest::getVar('formid', 0, 'get', 'int');
- }
-
- if($id){
- $query = "SELECT * FROM #__chrono_contact WHERE id = '$id'";
- $database->setQuery( $query );
- $rows = $database->loadObjectList();
- $paramsvalues = new JParameter($rows[0]->paramsall);
- $formtables = explode(",", $paramsvalues->get('tablenames'));
- }
-
- $table = JRequest::getVar('table', '');
-
- $result = $database->getTableList();
- if(!in_array($table, $result) || !$table){
- echo "<form action=\"index2.php\" method=\"post\" name=\"adminForm\">
- Table Doesn't Exist
- <input type=\"hidden\" name=\"task\" value=\"\" />
- <input type=\"hidden\" name=\"option\" value=\"$option\" />
- </form>";
- }else{
- $limit = $mainframe->getUserStateFromRequest($option.'.limit'.$table, 'limit', $mainframe->getCfg('list_limit'), 'int');
- $limitstart = $mainframe->getUserStateFromRequest($option.'.limitstart'.$table, 'limitstart', 0, 'int');
- // count entries
- $database->setQuery( "SELECT count(*) FROM ".$table );
- $total = $database->loadResult();
- echo $database->getErrorMsg();
- jimport('joomla.html.pagination');
- $pageNav = new JPagination($total, $limitstart, $limit);
- # main database query
- # get primary key
- $tables = array();
- $tables[] = $table;
- $result = $database->getTableFields( $tables, false );
- $table_fields = $result[$table];
- $primary = '';
- foreach($table_fields as $table_field => $field_data){
- if($field_data->Key == 'PRI')$primary = $table_field;
- }
- $order = "";
- if($primary) $order = " ORDER BY ".$primary;
- $database->setQuery( "SELECT * FROM ".$table.$order." LIMIT $pageNav->limitstart,$pageNav->limit" );
- $rows = $database->loadObjectList();
- if ($database->getErrorNum()) {
- JError::raiseWarning(100, $database->stderr());
- $mainframe->redirect( "index2.php?option=$option" );
- }
- $formid = $id;
- HTML_ChronoContact::showdataChronoContact( $rows, $pageNav, $option, $formid, $table );
- }
- }
- function viewdataChronoContact( $ids, $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- $fids = explode("_",$ids);
- $table = JRequest::getVar('table', '', 'post', 'string', 0);
- # get primary key
- $tables = array();
- $tables[] = $table;
- $result = $database->getTableFields( $tables, false );
- $table_fields = $result[$table];
- $primary = 'cf_id';
- foreach($table_fields as $table_field => $field_data){
- if($field_data->Key == 'PRI')$primary = $table_field;
- }
- $database->setQuery( "SELECT * FROM ".$table." WHERE ".$primary."=".$fids[0] );
- $rows = $database->loadObjectList();
- $row = $rows[0];
- $tablename = $table;
- //echo "SELECT * FROM ".$table." WHERE ".$primary."=".$fids[0];
- HTML_ChronoContact::viewdataChronoContact( $row, $option, $tablename, $fids[1] );
- }
- function tablemanagerChronoContact( $option ){
- global $mainframe;
- $database =& JFactory::getDBO();
- $result = $database->getTableList();
- HTML_ChronoContact::tablemanagerChronoContact($option, $result);
- }
- function maketableChronoContact( $id, $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- $query = "SELECT * FROM `#__components` WHERE `option` = 'com_chronocontact' AND parent='0' AND admin_menu_link='option=com_chronocontact'";
- $database->setQuery( $query );
- $result = $database->loadObject();
- //$configs = JComponentHelper::getParams('com_chronocontact');
- $configs = new JParameter($result->params);
-
- $table = JRequest::getVar('table');
- $result = $database->getTableList();
- if ($table) {
- $tables = array();
- $tables[] = $table;
- $result = $database->getTableFields( $tables, false );
- $table_fields = $result[$table];
-
- $row = new StdClass();
- $row->id = 0;
- HTML_ChronoContact::maketableChronoContact( $row, $option, $table, $table_fields );
- } else {
- $row =& JTable::getInstance('chronocontact', 'Table');
- $row->load( $id );
-
- $html_message = "";
-
- $multipagefields = '';
- $multipagefieldsnames = array();
- //check if form is a mother form and load childs fields
- $formparams = new JParameter($row->paramsall);
- $formplugins = explode(",", $formparams->get('plugins'));
- if(in_array('cf_multi_page', $formplugins)){
- $query = "SELECT * FROM #__chrono_contact_plugins WHERE `form_id` = '".$id."' AND name='cf_multi_page'";
- $database->setQuery( $query );
- $multipageconfig = $database->loadObject();
- $multipageparams = new JParameter($multipageconfig->params);
- $multipageforms = array();
- if(trim($multipageparams->get('formsnames'))){
- $multipageforms = explode(',', $multipageparams->get('formsnames'));
- $multipagefieldsnames = array();
- $multipagefields = array();
- }
- foreach($multipageforms as $multipageform){
- $query = "SELECT * FROM #__chrono_contact WHERE `name` = '".$multipageform."'";
- $database->setQuery( $query );
- $multipageformdata = $database->loadObject();
- $multipagefields[] = $multipageformdata->fieldsnames;
- }
- $multipagefieldsnames = explode(",", implode(",", $multipagefields));
- }
-
- $defaults = array('cf_id' => (object) array('Type' => 'INT(11)', 'Key' => 'PRI', 'Extra' => 'auto_increment'),
- 'uid' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''),
- 'recordtime' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''),
- 'ipaddress' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''),
- 'cf_user_id' => (object) array('Type' => 'VARCHAR(255)', 'Key' => '', 'Extra' => ''));
- $names = array();
- if(trim($row->fieldsnames)){
- $names = explode(",", $row->fieldsnames);
- }
- $fieldstypes = explode(",", $row->fieldstypes);
- foreach($names as $name){
- $defaults[$name] = (object) array('Type' => '', 'Key' => '', 'Extra' => '');
- }
- if(count($multipagefieldsnames)){
- foreach($multipagefieldsnames as $multipagefieldsname){
- $defaults[$multipagefieldsname] = (object) array('Type' => '', 'Key' => '', 'Extra' => '');
- }
- }
- HTML_ChronoContact::maketableChronoContact( $row, $option, '', $defaults );
- }
- }
- function finalizetableChronoContact( $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- $id = JRequest::getVar('formid');
- $table = JRequest::getVar('istable_name');
- $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
- $table_sql_arr = array();
- $primarykey = '';
-
- if($id){
- $row =& JTable::getInstance('chronocontact', 'Table');
- $row->load( $id );
- $paramsvalues = new JParameter($row->paramsall);
-
- if(is_array($post['fields'])){
- foreach($post['fields'] as $k => $field){
- if($field && $post['fields_enable'][$k]){
- $sqlpiece = '`'.$field.'` '.$post['fields_types'][$k].' NOT NULL';
- if(JRequest::getVar('isautoincrement') == $field){
- $sqlpiece .= " auto_increment";
- }
- if(JRequest::getVar('iskey') == $field){
- $primarykey = "PRIMARY KEY (`".$field."`)";
- }
- $table_sql_arr[] = $sqlpiece;
- }
- }
- }
- if($primarykey){
- $table_sql_arr[] = $primarykey;
- }
- if ( count($post['fields']) > 0){
- $table_sql = "CREATE TABLE `".JRequest::getVar('istable_name')."` (";
- $table_sql .= implode(", ", $table_sql_arr);
- if ($paramsvalues->get('mysql_type', 0) == 2){
- $table_sql .= ") TYPE = MYISAM ;";
- } else{
- $table_sql .= ") ENGINE = MYISAM ;";
- }
- }
- }else{
- if($table){
- $result = $database->getTableList();
- $table_sql = '';
- if(in_array(JRequest::getVar('tableexists'), $result)){
- //rename table if name was changed
- if($table != JRequest::getVar('tableexists')){
- $database->setQuery('RENAME TABLE `'.JRequest::getVar('tableexists').'` TO `'.$table.'`');
- if (!$database->query()) {
- $mainframe->redirect( 'index2.php?option='.$option, "Error while renaming table :".$database->getErrorMsg() );
- }
- }
- $tables = array();
- $tables[] = $table;
- $result = $database->getTableFields( $tables, false );
- $table_fields = $result[$table];
-
- if(is_array($post['fields'])){
- foreach($post['fields'] as $k => $field){
- $found = false;
- $sqlpiece = '';
- if($field && $post['fields_enable'][$k]){
- foreach($table_fields as $fieldname => $fielddata){
- if($field == $fieldname){
- $found = true;
- break;
- }
- }
- if(!$found){
- $sqlpiece = 'ADD COLUMN `'.$field.'` '.$post['fields_types'][$k].' NOT NULL';
- }
- if((JRequest::getVar('isautoincrement') == $field)&&$sqlpiece){
- $sqlpiece .= " auto_increment";
- }
- if((JRequest::getVar('iskey') == $field)&&(JRequest::getVar('isoldkey') != $field)){
- $primarykey = "DROP PRIMARY KEY, ADD PRIMARY KEY (`".$field."`)";
- }
- if($sqlpiece){
- $table_sql_arr[] = $sqlpiece;
- }
- }
- if($field && !$post['fields_enable'][$k] && in_array($field, array_keys($table_fields))){
- $table_sql_arr[] = 'DROP `'.$field.'`';
- }
- }
- if($primarykey){
- $table_sql_arr[] = $primarykey;
- }
- if(implode(", ", $table_sql_arr)){
- $table_sql = 'ALTER TABLE '.$table.' '.implode(", ", $table_sql_arr).';';
- }
- }
-
- }
- }
- }
-
- $success_message = ($id) ? "Table has been created successfully" : "Table has been updated successfully";
- if($table_sql){
- $database->setQuery( $table_sql );
- if (!$database->query()) {
- $mainframe->redirect( 'index2.php?option='.$option, "Error while creating table :".$database->getErrorMsg() );
- }else{
- $mainframe->redirect( 'index2.php?option='.$option, $success_message );
- }
- }else{
- $mainframe->redirect( 'index2.php?option='.$option, "Your changes have been applied" );
- }
-
- }
- function updatetablelistChronoContact( $option ) {
- global $mainframe;
- $database =& JFactory::getDBO();
- $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
-
- $table_sql_arr = array();
- if(is_array($post['tables'])){
- foreach($post['tables'] as $k => $table){
- if($table && !$post['tables_enable'][$k]){
- $sqlpiece = '`'.$table.'`';
- $table_sql_arr[] = $sqlpiece;
- }
- }
- }
-
- if(count($table_sql_arr)){
- $table_sql = 'DROP TABLE IF EXISTS '.implode(", ", $table_sql_arr).';';
- $database->setQuery( $table_sql );
- if (!$database->query()) {
- $mainframe->redirect( 'index2.php?option='.$option, "Error:".$database->getErrorMsg() );
- }else{
- $mainframe->redirect( 'index2.php?option='.$option, "Tables list updated successfully" );
- }
- }else{
- $mainframe->redirect( 'index2.php?option='.$option, "No changes have been made" );
- }
-
- }
- /* backup ****************************************************/
- function backupChronoContact( $id, $option, $task ){
- global $mainframe;
- $database =& JFactory::getDBO();
- if($task == 'backup'){
- $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$id."'" );
- $rows = $database->loadObjectList();
-
-
- $tablename = $mainframe->getCfg('dbprefix')."chrono_contact";
- $tables = array( $tablename );
- $result = $database->getTableFields( $tables );
- $table_fields = array_keys($result[$tablename]);
- $string = '';
- foreach($table_fields as $table_field){
- $string .= '<++-++-++'.$table_field.'++-++-++>';
- $string .= $rows[0]->$table_field;
- $string .= '<endendend>';
- }
-
- $database->setQuery( "SELECT * FROM #__chrono_contact_emails WHERE formid='".$id."' ORDER BY emailid" );
- $emails = $database->loadObjectList();
- $tablename = $mainframe->getCfg('dbprefix')."chrono_contact_emails";
- $tables = array( $tablename );
- $result = $database->getTableFields( $tables );
- $table_fields = array_keys($result[$tablename]);
- $string2 = '';
- foreach($emails as $email){
- foreach($table_fields as $table_field){
- $string2 .= '<2++-++-++'.$table_field.'++-++-++>';
- $string2 .= $email->$table_field;
- $string2 .= '<endendend2>';
- }
- $string2 .= '<cf_email_separator>';
- }
- if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
- $UserBrowser = "Opera";
- }
- elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
- $UserBrowser = "IE";
- } else {
- $UserBrowser = '';
- }
- $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
- @ob_end_clean();
- ob_start();
-
- header('Content-Type: ' . $mime_type);
- header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
-
- if ($UserBrowser == 'IE') {
- header('Content-Disposition: inline; filename="' . $rows[0]->name.'.cfbak"');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- }
- else {
- header('Content-Disposition: attachment; filename="' . $rows[0]->name.'.cfbak"');
- header('Pragma: no-cache');
- }
- print $string.'
- {cfbak_start_emails}
- '.$string2.'
- {cfbak_end_emails}';
- exit();
-
-
- }else{
- $doc = new DomDocument('1.0', 'UTF-8');
- $root = $doc->createElement('root');
- $root = $doc->appendChild($root);
-
- $database->setQuery( "SELECT * FROM #__chrono_contact" );
- $forms = $database->loadObjectList();
- $tablename = $mainframe->getCfg('dbprefix')."chrono_contact";
- $tables = array( $tablename );
- $result = $database->getTableFields( $tables );
- $table_fields = array_keys($result[$tablename]);
-
- foreach($forms as $form){
- $occ = $doc->createElement("form_".$form->name);
- $occ = $root->appendChild($occ);
-
- foreach($table_fields as $table_field){
- $child = $doc->createElement($table_field);
- $child = $occ->appendChild($child);
- $value = $doc->createTextNode($form->$table_field);
- $value = $child->appendChild($value);
- }
- //list emails
- $database->setQuery( "SELECT * FROM #__chrono_contact_emails WHERE formid='".$form->id."' ORDER BY emailid" );
- $emails = $database->loadObjectList();
- $tablename_email = $mainframe->getCfg('dbprefix')."chrono_contact_emails";
- $tables_email = array( $tablename_email );
- $result_email = $database->getTableFields( $tables_email );
- $table_fields_email = array_keys($result_email[$tablename_email]);
-
- $child = $doc->createElement("emails");
- $child = $occ->appendChild($child);
- foreach($emails as $email){
- $occ_email = $doc->createElement("email".$email->emailid);
- $occ_email = $child->appendChild($occ_email);
-
- foreach($table_fields_email as $table_field_email){
- $child_email = $doc->createElement($table_field_email);
- $child_email = $occ_email->appendChild($child_email);
- $value_email = $doc->createTextNode($email->$table_field_email);
- $value_email = $child_email->appendChild($value_email);
- }
- }
- //list plugins
- $database->setQuery( "SELECT * FROM #__chrono_contact_plugins WHERE id='".$form->id."' ORDER BY id" );
- $plugins = $database->loadObjectList();
- $tablename_plugin = $mainframe->getCfg('dbprefix')."chrono_contact_plugins";
- $tables_plugin = array( $tablename_plugin );
- $result_plugin = $database->getTableFields( $tables_plugin );
- $table_fields_plugin = array_keys($result_plugin[$tablename_plugin]);
-
- $child = $doc->createElement("plugins");
- $child = $occ->appendChild($child);
- foreach($plugins as $plugin){
- $occ_plugin = $doc->createElement($plugin->name);
- $occ_plugin = $child->appendChild($occ_plugin);
-
- foreach($table_fields_plugin as $table_field_plugin){
- $child_plugin = $doc->createElement($table_field_plugin);
- $child_plugin = $occ_plugin->appendChild($child_plugin);
- $value_plugin = $doc->createTextNode($plugin->$table_field_plugin);
- $value_plugin = $child_plugin->appendChild($value_plugin);
- }
- }
- }
-
- $xml_string = $doc->saveXML();
-
- if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
- $UserBrowser = "Opera";
- }
- elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
- $UserBrowser = "IE";
- } else {
- $UserBrowser = '';
- }
- $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
- @ob_end_clean();
- ob_start();
-
- header('Content-Type: ' . $mime_type);
- header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
-
- if ($UserBrowser == 'IE') {
- header('Content-Disposition: inline; filename="' . "ALL_".date('d_M_Y_H:i:s').'.cfxbak"');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- }
- else {
- header('Content-Disposition: attachment; filename="' . "ALL_".date('d_M_Y_H:i:s').'.cfxbak"');
- header('Pragma: no-cache');
- }
- print $xml_string;
- exit();
- }
-
- /*if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
- $UserBrowser = "Opera";
- }
- elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) {
- $UserBrowser = "IE";
- } else {
- $UserBrowser = '';
- }
- $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
- @ob_end_clean();
- ob_start();
- header('Content-Type: ' . $mime_type);
- header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
- if ($UserBrowser == 'IE') {
- header('Content-Disposition: inline; filename="' . $rows[0]->name.'.cfbak"');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- }
- else {
- header('Content-Disposition: attachment; filename="' . $rows[0]->name.'.cfbak"');
- header('Pragma: no-cache');
- }
- print $string.'
- {cfbak_start_emails}
- '.$string2.'
- {cfbak_end_emails}';
- exit();
- */
- }
- function restore1ChronoContact( $id, $option ){
- HTML_ChronoContact::restoreChronoContact( $id, $option );
- }
- function restore2ChronoContact( $id, $option ){
- global $mainframe;
- $database =& JFactory::getDBO();
- jimport('joomla.utilities.error');
- jimport('joomla.filesystem.file');
- $id = JRequest::getVar('formid');
- //echo $_FILES['file']['type'];
- if(is_array(JRequest::getVar( 'file', '', 'files', 'array' ))){
- $file = JRequest::getVar( 'file', '', 'files', 'array' );
- $filename = $file['name'];
- $exten = explode(".",$filename);
- if($exten[count($exten)-1] == 'cfbak'){
- //if($_FILES['file']['type'] == "application/octet-stream"){
- //$filename = $_FILES['file']['name'];
-
- $path = JPATH_BASE.DS.'cache';
- $uploadedfile = JFile::upload($file['tmp_name'], $path.DS.$filename);
- //if( is_writable($path) ) {
- if(!$uploadedfile) {
- print "<fon…
Large files files are truncated, but you can click here to view the full file