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('/\<++(.*?)\/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('','',$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('', $data); $fields_count_1 = explode('{cfbak_start_emails}', $emails_count[0]); $fields_count_2 = explode('', $fields_count_1[1]); preg_match_all('/\<2++(.*?)\/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('','',$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 here 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 .= "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.'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 "
Table Doesn't Exist
"; }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 .= ''; } $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 .= ''; } $string2 .= ''; } 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 ""."UPLAOD FAILED".": " . $file['error'] . "
\n"; JError::raiseWarning(100, "UPLAOD FAILED".": " . $file['error']); $mainframe->redirect( "index2.php?option=$option" ); } else { $data = file_get_contents( $path.DS.$filename ); $data = str_replace( '&', '&', $data ); $values = '('; $values2 = '('; //print $data; preg_match_all('/\<++(.*?)\/s', $data, $matches); $i = 0; foreach ( $matches[0] as $match ) { if($i != 0){$values .= ',';$values2 .= ',';} //echo $match.'x'; 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('','',$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('', $data); $fields_count_1 = explode('{cfbak_start_emails}', $emails_count[0]); $fields_count_2 = explode('', $fields_count_1[1]); preg_match_all('/\<2++(.*?)\/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('','',$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 , "Restored successfully"); } //} }else if($exten[count($exten)-1] == 'cfxbak'){ $path = JPATH_BASE.DS.'cache'; $uploadedfile = JFile::upload($file['tmp_name'], $path.DS.$filename); if(!$uploadedfile) { print ""."UPLAOD FAILED".": " . $file['error'] . "
\n"; JError::raiseWarning(100, "UPLAOD FAILED".": " . $file['error']); $mainframe->redirect( "index2.php?option=$option" ); } else { $data = file_get_contents( $path.DS.$filename ); $data = str_replace( '&', '&', $data ); $xml = simplexml_load_file($path.DS.$filename); $post = array(); $post_email = array(); $post_plugin = array(); foreach($xml->children() as $form){ foreach($form->children() as $field){ $post[$field->getName()] = (string)$field; if($field->getName() == 'emails'){ if(count($field->children())){ foreach($field->children() as $k => $email){ foreach($email->children() as $emaildata){ $post_email[$k][$emaildata->getName()] = (string)$emaildata; } } } } if($field->getName() == 'plugins'){ if(count($field->children())){ foreach($field->children() as $k => $plugin){ foreach($plugin->children() as $plugindata){ $post_plugin[$k][$plugindata->getName()] = (string)$plugindata; } } } } } $row =& JTable::getInstance('chronocontact', 'Table'); $post['id'] = ''; if (!$row->bind( $post )) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } if (!$row->store()) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } foreach($post_email as $k => $email){ $email['formid'] = $row->id; $email['emailid'] = ''; $row_email =& JTable::getInstance('chronocontactemails', 'Table'); if (!$row_email->bind( $email )) { JError::raiseWarning(100, $row_email->getError()); $mainframe->redirect( "index2.php?option=$option" ); } if (!$row_email->store()) { JError::raiseWarning(100, $row_email->getError()); $mainframe->redirect( "index2.php?option=$option" ); } } foreach($post_plugin as $k => $plugin){ $plugin['form_id'] = $row->id; $plugin['id'] = ''; $row_plugin =& JTable::getInstance('chronocontactplugins', 'Table'); if (!$row_plugin->bind( $plugin )) { JError::raiseWarning(100, $row_plugin->getError()); $mainframe->redirect( "index2.php?option=$option" ); } if (!$row_plugin->store()) { JError::raiseWarning(100, $row_plugin->getError()); $mainframe->redirect( "index2.php?option=$option" ); } } $post = array(); $post_email = array(); $post_plugin = array(); } $mainframe->redirect( 'index2.php?option='.$option , "Restored all data successfully"); } }else{ echo "Sorry, But this is not a valid ChronoForms backup file, Backup files should end with .cfbak"; } } } function BackupExcel( $id, $option ) { global $mainframe; $database =& JFactory::getDBO(); include_once JPATH_BASE.DS.'/components/com_chronocontact/excelwriter/'."Writer.php"; //echo $_POST['formid']; $formid = JRequest::getVar( 'formid', array(), 'post', 'array'); $database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$formid[0]."'" ); $formname = $database->loadResult(); $tablename = JRequest::getVar('table'); $tables = array( $tablename ); $result = $database->getTableFields( $tables ); $table_fields = array_keys($result[$tablename]); $database->setQuery( "SELECT * FROM ".$tablename."" ); $datarows = $database->loadObjectList(); $xls =& new Spreadsheet_Excel_Writer(); $xls->setVersion(8); // this fixes the 255 limit issue! :) $xls->send("ChronoForms_".$formname."_".date("j_n_Y").".xls"); $format =& $xls->addFormat(); $format->setBold(); $format->setColor("blue"); if (strlen($formname) > 10){$formname = substr($formname,0,10);}; $sheet =& $xls->addWorksheet($formname.' at '.date("m-d-Y")); $sheet->setInputEncoding('utf-8'); $titcol = 0; foreach($table_fields as $table_field){ $sheet->writeString(0, $titcol, $table_field, $format); $titcol++; } $datacol = 0; $rowcount = 1; foreach($datarows as $datarow){ foreach($table_fields as $table_field){ $sheet->writeString($rowcount, $datacol, $datarow->$table_field, 0); $datacol++; } $datacol = 0; $rowcount++; } $xls->close(); exit; } function deleterecordChronoContact( $cid_del, $option ) { global $mainframe; $database =& JFactory::getDBO(); //echo $cid_del[0]; $cid_del_arr = array(); foreach($cid_del as $cid_del_1){ $fids = explode("_",$cid_del_1); $cid_del_arr[] = $fids[0]; $formid = $fids[1]; } $cid_dels = implode( ',', $cid_del_arr ); if (!is_array( $cid_del ) || count( $cid_del ) < 1) { JError::raiseWarning(100, 'Please select an entry to delete'); showdataChronoContact( $formid, $option ); } # get primary key $tables = array(); $table = JRequest::getVar('table'); $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( "DELETE FROM ".$table." WHERE ".$primary." IN ($cid_dels)" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); showdataChronoContact( $formid, $option ); } showdataChronoContact( $formid, $option ); } function BackupCSV( $id, $option ) { global $mainframe; $database =& JFactory::getDBO(); include_once JPATH_BASE.'/components/com_chronocontact/excelwriter/'."Writer.php"; //echo $_POST['formid']; $formid = JRequest::getVar( 'formid', array(), 'post', 'array'); $database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$formid[0]."'" ); $formname = $database->loadResult(); $tablename = JRequest::getVar('table'); $tables = array( $tablename ); $result = $database->getTableFields( $tables ); $table_fields = array_keys($result[$tablename]); $database->setQuery( "SELECT * FROM ".$tablename."" ); $datarows = $database->loadObjectList(); $titcol = 0; foreach($table_fields as $table_field){ if($titcol){$csvline .=",";} $csvline .= $table_field; $titcol++; } $csvline .="\n"; $datacol = 0; $rowcount = 1; foreach($datarows as $datarow){ foreach($table_fields as $table_field){ if($datacol){$csvline .=",";} $csvline .= '"'.addslashes($datarow->$table_field).'"'; $datacol++; } $csvline .="\n"; $datacol = 0; $rowcount++; } 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="' . "ChronoForms - ".$formname." - ".date("j_n_Y").'.csv"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Content-Disposition: attachment; filename="' . "ChronoForms - ".$formname." - ".date("j_n_Y").'.csv"'); header('Pragma: no-cache'); } print $csvline; exit(); } function deletetableChronoContact( $id, $option ){ global $mainframe; $database =& JFactory::getDBO(); $result = $database->getTableList(); if (!in_array($mainframe->getCfg('dbprefix')."chronoforms_".$id, $result)) { JError::raiseWarning(100, "There is no table for this form to delete"); $mainframe->redirect( "index2.php?option=$option" ); }else{ $database->setQuery( "DROP TABLE IF EXISTS `#__chronoforms_".$id."`;" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); $mainframe->redirect( "index2.php?option=$option" ); }else{ $mainframe->redirect( 'index2.php?option='.$option , "Table Deleted successfully"); } } } function menu_creator($option){ HTML_ChronoContact::menu_creator( $option ); } function menu_save($option){ global $mainframe; $database =& JFactory::getDBO(); JTable::addIncludePath(JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'database'.DS.'table'); $row =& JTable::getInstance('component', 'JTable'); //$row->load(1); $row->name = JRequest::getVar('linktext'); $row->parent = JRequest::getVar('parent'); $row->ordering = JRequest::getVar('ordering'); $row->admin_menu_link = "option=com_chronocontact&task=show&formid=".JRequest::getVar('form_id'); $row->admin_menu_img = "js/ThemeOffice/".JRequest::getVar('icon'); $row->option = "com_chronocontact"; $row->link = "option=com_chronocontact&task=show&formid=1"; $row->admin_menu_alt = JRequest::getVar('linktext'); if (!$row->store()) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } $mainframe->redirect( 'index2.php?option='.$option , "Menu Item Created"); } function menu_remover($option){ HTML_ChronoContact::menu_remover( $option ); } function menu_delete( $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 #__components WHERE id IN ($cids)" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); $mainframe->redirect( "index2.php?option=$option" ); } $mainframe->redirect( 'index2.php?option='.$option.'&task=menu_remover' , "Menu Item Deleted"); } function form_wizard($id, $option){ global $mainframe; $htmloutput = ''; $database =& JFactory::getDBO(); $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$id."'" ); $row = $database->loadObject(); if($id){ if(!trim($row->chronocode)){ $mainframe->redirect( 'index2.php?option='.$option , "Sorry but this form was not created using the wizard"); } define('CPHP_EOL', "\n"); $old_chrono_code = $row->chronocode; $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode); $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode); $htmlcode = ''; $htmloutput = ''; //load theme ob_start(); require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."wizardthemes".DS.'default'.DS."elements.php"); $theme_elements = ob_get_clean(); foreach($XHTMLELEMENTS as $XHTMLELEMENT){ if(trim($XHTMLELEMENT)){ $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT); $thiselement = array(); $counter = 0; foreach($element_pieces as $element_piece){ if(($element_piece != '{')&&($element_piece != '}')&&($counter > 0)){ $linepieces = explode(" = ", $element_piece); if(count($linepieces) == 2){ $thiselement[trim($linepieces[0])] = $linepieces[1]; }else{ $thiselement[trim($linepieces[0])] = ''; } } $counter++; } //get element tag $element_type = ''; if (preg_match("/\[type=\".*?\"/i", $element_pieces[0], $matches)) { $element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]); } else { continue; } //get element from theme file $element_theme_1 = explode("", $theme_elements); $element_theme_2 = explode("", $element_theme_1[1]); //fill the element theme foreach($thiselement as $k => $v){ $element_theme_2[0] = str_replace('{cf_'.$k.'}', $v, $element_theme_2[0]); } if (preg_match("/(.*?)<\/cf_theoptions>/is", $element_theme_2[0], $matches2)) { //echo str_replace("<", "[", $matches2[0]);//$element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]); $option_element = str_replace(array('', '') , array('', ''), $matches2[0]); $options = explode("*,*" , $thiselement['theoptions']); $optionsdata = ''; $icounter = 0; foreach($options as $option){ if(trim($option)){ $optionsdata .= str_replace(array('{value}', '{title}', '{name}'), array($option, $option, str_replace(array('[',']'), array('', '') , $thiselement['name']).$icounter), $option_element); $optionsdata .= CPHP_EOL; $icounter++; } } $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]); }else if(preg_match("/(.*?)<\/cf_thecells>/is", $element_theme_2[0], $matches2)) { $option_element = str_replace(array('', '') , array('', ''), $matches2[0]); $options = explode("*,*" , $thiselement['thecells']); $optionsdata = ''; $icounter = 0; foreach($options as $option){ if(trim($option)){ $optionsdata .= str_replace(array('{value}'), array($option), $option_element); $optionsdata .= CPHP_EOL; $icounter++; } } $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]); } else{ //echo 'not found
'; } $htmloutput .= $element_theme_2[0]; //add the tooltips and label styles if(trim($thiselement['tooltiptext'])){ $htmloutput = str_replace("{cf_tooltip}", ' ', $htmloutput); }else{ $htmloutput = str_replace("{cf_tooltip}", "", $htmloutput); } if(trim($thiselement['tooltiptext'])){ $cf_tooltip2 = explode(" :: ", trim($thiselement['tooltiptext'])); $htmloutput = str_replace("{cf_tooltip2}", $cf_tooltip2[1], $htmloutput); }else{ $htmloutput = str_replace("{cf_tooltip2}", "", $htmloutput); } if(($element_pieces[0] == '[type="cf_button"')){ if(trim($thiselement['reset']) == '1'){ $htmloutput = str_replace("{cf_resetbutton}", '', $htmloutput); }else{ $htmloutput = str_replace("{cf_resetbutton}", "", $htmloutput); } } if(trim($thiselement['hidelabel']) == '1'){ $htmloutput = str_replace("{cf_labeloptions}", ' style="display: none;"', $htmloutput); }else if((trim($thiselement['labelwidth']) != 'auto')&&(trim($thiselement['labelwidth']) != '0px')){ $htmloutput = str_replace("{cf_labeloptions}", ' style="width: '.trim($thiselement['labelwidth']).';"', $htmloutput); }else{ $htmloutput = str_replace("{cf_labeloptions}", "", $htmloutput); } if(($element_pieces[0] == '[type="cf_dropdown"')){ if((int)$thiselement['size'] > 1){ $htmloutput = str_replace("{cf_multiple}", 'multiple="multiple"', $htmloutput); }else{ $htmloutput = str_replace("{cf_multiple}", '', $htmloutput); } } if(($element_pieces[0] == '[type="cf_placeholder"')){ $database->setQuery( "SELECT * FROM #__chrono_contact_elements WHERE placeholder='".$thiselement['labeltext']."' ORDER BY id" ); $placeholder = $database->loadObject(); if($placeholder){ $htmloutput = str_replace("{cf_element_id}", $placeholder->id, $htmloutput); $htmloutput = str_replace("{cf_params}", str_replace("\n", "*,*", $placeholder->params), $htmloutput); $wizardelementparams = explode("\n", $placeholder->params); $paramsatts = ""; foreach($wizardelementparams as $wizardelementparam){ if(trim($wizardelementparam)){ $paramdata = explode('=', $wizardelementparam); $paramsatts .= $paramdata[0].'="'.$thiselement[$paramdata[0]].'" '; } } $htmloutput = str_replace("{cf_params_elements}", $paramsatts, $htmloutput); }else{ $htmloutput = str_replace("{cf_multiple}", '', $htmloutput); } } } } } HTML_ChronoContact::form_wizard( $htmloutput, $row, $option ); } function save_form_wizard( $option ){ $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW ); if($post['formid'])$post['id'] = $post['formid']; $post['html'] = $post['form_code_temp']; $post['name'] = $post['form_title_temp']; $post['redirecturl'] = $post['redirecturl']; $post['onsubmitcode'] = $post['onsubmitcode']; if(!$post['formid']){ $params = array(); $params[] = "formmethod=post"; $params[] = "omittedfields="; $params[] = "LoadFiles=Yes"; $params[] = "submissions_limit="; $params[] = "tablenames="; $params[] = "savedataorder="; $params[] = "handlepostedarrays="; $params[] = "debug=0"; $params[] = "mysql_type=1"; $params[] = "enmambots=No"; $params[] = "uploads=".($post['uploadfields'] ? 'Yes' : 'No').""; $params[] = "uploadfields=".$post['uploadfields'].""; $params[] = "uploadmax="; $params[] = "uploadmin="; $params[] = "uploadpath="; $params[] = "dvfields="; $params[] = "dvrecord=Record #n"; $params[] = "imagever=No"; $params[] = "imtype=0"; $params[] = "captcha_dataload=0"; $params[] = "imgver_error_msg="; $params[] = "validate=No"; $params[] = "servervalidate="; $params[] = "validatetype=mootools"; $params[] = "val_required="; $params[] = "val_validate_number="; $params[] = "val_validate_digits="; $params[] = "val_validate_alpha="; $params[] = "val_validate_alphanum="; $params[] = "val_validate_date="; $params[] = "val_validate_email="; $params[] = "val_validate_url="; $params[] = "val_validate_date_au="; $params[] = "val_validate_currency_dollar="; $params[] = "val_validate_selection="; $params[] = "val_validate_one_required="; $params[] = "val_validate_confirmation="; $params[] = "plugins="; $params[] = "plugins_order=1"; $params[] = "onsubmitcode_order=2"; $params[] = "autogenerated_order=3"; $params[] = "mplugins_order="; $params[] = "dbconnection="; $params[] = "datefieldformat=d/m/Y"; $params[] = "datefieldsnames=".$post['datefieldsnames']; $post['paramsall'] = implode("\n", $params); }else{ $params = JRequest::getVar( 'params', array(), 'post', 'array'); if (is_array( $params )) { $txt = array(); if($post['uploadfields']){ $params['uploads'] = 'Yes'; $params['uploadfields'] = $post['uploadfields']; $params['LoadFiles'] = 'Yes'; } foreach ( $params as $k=>$v) { if($k == 'datefieldsnames')$v = $post['datefieldsnames']; $txt[] = "$k=$v"; } $post['paramsall'] = implode( "\n", $txt ); } } //print_r($post); global $mainframe; $database =& JFactory::getDBO(); $row =& JTable::getInstance('chronocontact', 'Table'); if (!$row->bind( $post )) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } //auto transform to default //defined('PHP_EOL') or define('PHP_EOL', '\r\n'); define('CPHP_EOL', "\n"); $old_chrono_code = $row->chronocode; $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode); $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode); $htmlcode = ''; $htmloutput = ''; $emailoutput = ''; //load theme ob_start(); require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.'default'.DS."elements.php"); $theme_elements = ob_get_clean(); ob_start(); require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.'default'.DS."email.php"); $email_template = ob_get_clean(); $WizardOutput = GetWizardOutput($XHTMLELEMENTS, $theme_elements, $email_template); $OmittedElements = $WizardOutput['omitted']; foreach($OmittedElements as $OmittedElement){ $WizardOutput['theme'][$OmittedElement] = ''; } $htmloutput = implode('', $WizardOutput['theme']); $emailoutput = implode('', $WizardOutput['email']); $row->html = $htmloutput; $row->chronocode = $old_chrono_code; $FieldsNamesTypes = generateFieldsNamesTypes($row->html); $row->fieldsnames = implode(",", $FieldsNamesTypes["names"]); $row->fieldstypes = implode(",", $FieldsNamesTypes["types"]); //end auto transform if (!$row->store()) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option" ); } //$mainframe->redirect( "index2.php?option=$option", 'Form Saved, you can Open form to edit other settings now!' ); //$emailsids = JRequest::getVar( 'emailsids', array(), 'post', 'array'); if($post['formid']){ //Delet old emails and save new clean ones $database->setQuery( "DELETE FROM #__chrono_contact_emails WHERE formid = '".$post['formid']."'" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); $mainframe->redirect( "index2.php?option=$option" ); } } $emailslist = explode(",", $post['emailslist']); $emailslist_clean = array(); foreach($emailslist as $emaillist){ if(trim($emaillist)){ $emailslist_clean[] = $emaillist; } } preg_match_all('/start_email{.*?}end_email/i', $post['emails_temp'], $matches); $emails = array(); $template_count = 0; foreach ( $matches[0] as $email ) { //echo $email; $email = preg_replace('/start_email{/i', '', $email); $email = preg_replace('/}end_email/i', '', $email); $email_elements = explode('||', $email); //$emails[] = trim($email); $post2 = array(); $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_'.$emailslist_clean[$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['enabled'] = $params[2]; $post2['template'] = trim($post['editor_'.$emailslist_clean[$template_count]]) ? trim($post['editor_'.$emailslist_clean[$template_count]]) : trim($emailoutput); $template_count++; $row2 =& JTable::getInstance('chronocontactemails', 'Table'); if (!$row2->bind( $post2 )) { JError::raiseWarning(100, $row2->getError()); } if (!$row2->store()) { JError::raiseWarning(100, $row2->getError()); } } $mainframe->redirect( "index2.php?option=$option", 'Form Saved, you can Open form to edit other settings now!' ); //$emails = array_unique($emails); } function GetWizardOutput($XHTMLELEMENTS, $theme_elements, $email_template){ global $mainframe; $database =& JFactory::getDBO(); $ClearElements = array(); $ClearElements_Email = array(); $OmittedElements = array(); foreach($XHTMLELEMENTS as $XHTMLELEMENT){ if(trim($XHTMLELEMENT)){ $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT); $thiselement = array(); $counter = 0; foreach($element_pieces as $element_piece){ if(($element_piece != '{')&&($element_piece != '}')&&($counter > 0)){ $linepieces = explode(" = ", $element_piece); if(count($linepieces) == 2){ $thiselement[trim($linepieces[0])] = $linepieces[1]; }else{ $thiselement[trim($linepieces[0])] = ''; } } $counter++; } //get element tag $element_type = ''; if (preg_match("/\[type=\".*?\"/i", $element_pieces[0], $matches)) { $element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]); } else { continue; } //get element from theme file $element_theme_1 = explode("", $theme_elements); $element_theme_2 = explode("", $element_theme_1[1]); if($email_template){ $element_email_1 = explode("", $email_template); $element_email_2 = explode("", $element_email_1[1]); } //fill the element theme foreach($thiselement as $k => $v){ $element_theme_2[0] = str_replace('{cf_'.$k.'}', $v, $element_theme_2[0]); } if($email_template){ foreach($thiselement as $k => $v){ $element_email_2[0] = str_replace('{cf_'.$k.'}', $v, $element_email_2[0]); $element_email_2[0] = str_replace('{cf_cf_'.$k.'}', '{'.str_replace("[]", "", $v).'}', $element_email_2[0]); } } if (preg_match("/(.*?)<\/cf_theoptions>/is", $element_theme_2[0], $matches2)) { //echo str_replace("<", "[", $matches2[0]);//$element_type = str_replace(array('[type="', '"'), array('',''), $element_pieces[0]); $option_element = str_replace(array('', '') , array('', ''), $matches2[0]); $theoptions = explode("*,*" , $thiselement['theoptions']); $optionsdata = ''; $icounter = 0; foreach($theoptions as $theoption){ if(trim($theoption)){ $optionsdata .= str_replace(array('{value}', '{title}', '{name}'), array($theoption, $theoption, str_replace(array('[',']'), array('', '') , $thiselement['name']).$icounter), $option_element); $optionsdata .= CPHP_EOL; $icounter++; } } $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]); }else if(preg_match("/(.*?)<\/cf_thecells>/is", $element_theme_2[0], $matches2)) { $option_element = str_replace(array('', '') , array('', ''), $matches2[0]); $theoptions = explode("*,*" , $thiselement['thecells']); $optionsdata = ''; $icounter = 0; foreach($theoptions as $theoption){ if(trim($theoption)){ $optionsdata .= str_replace(array('{element}'), array($ClearElements[$theoption - 1]), $option_element); $optionsdata .= CPHP_EOL; $OmittedElements[] = $theoption - 1; $icounter++; } } $element_theme_2[0] = str_replace($matches2[0], $optionsdata, $element_theme_2[0]); } else{ //echo 'not found
'; } //add the tooltips and label styles if(trim($thiselement['tooltiptext'])){ $element_theme_2[0] = str_replace("{cf_tooltip}", '
'.trim($thiselement['tooltiptext']).'
', $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_tooltip}", "", $element_theme_2[0]); } if(trim($thiselement['tooltiptext'])){ $cf_tooltip2 = explode(" :: ", trim($thiselement['tooltiptext'])); $element_theme_2[0] = str_replace("{cf_tooltip2}", $cf_tooltip2[1], $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_tooltip2}", "", $element_theme_2[0]); } if(($element_pieces[0] == '[type="cf_button"')){ if(trim($thiselement['reset']) == '1'){ $element_theme_2[0] = str_replace("{cf_resetbutton}", '', $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_resetbutton}", "", $element_theme_2[0]); } } if(($element_pieces[0] == '[type="cf_placeholder"')){ $database->setQuery( "SELECT * FROM #__chrono_contact_elements WHERE placeholder='".$thiselement['labeltext']."' ORDER BY id" ); $placeholder = $database->loadObject(); if($placeholder){ $wizardelementparams = explode("\n", $placeholder->params); foreach($wizardelementparams as $wizardelementparam){ if(trim($wizardelementparam)){ $paramdata = explode('=', $wizardelementparam); $placeholder->code = str_replace("{".$paramdata[0]."}", $thiselement[$paramdata[0]], $placeholder->code); } } $element_theme_2[0] = str_replace("{cf_codeplace}", $placeholder->code, $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_codeplace}", "", $element_theme_2[0]); } } if(trim($thiselement['hidelabel']) == '1'){ $element_theme_2[0] = str_replace("{cf_labeloptions}", ' style="display: none;"', $element_theme_2[0]); }else if((trim($thiselement['labelwidth']) != 'auto')&&(trim($thiselement['labelwidth']) != '0px')){ $element_theme_2[0] = str_replace("{cf_labeloptions}", ' style="width: '.trim($thiselement['labelwidth']).';"', $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_labeloptions}", ' style="width: 150px;"', $element_theme_2[0]); } if(($element_pieces[0] == '[type="cf_dropdown"')){ if((int)$thiselement['size'] > 1){ $element_theme_2[0] = str_replace("{cf_multiple}", 'multiple="multiple"', $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_multiple}", '', $element_theme_2[0]); } } if(($element_pieces[0] == '[type="cf_dropdown"')){ if($thiselement['firstoption']){ $element_theme_2[0] = str_replace("{cf_firstoptiondata}", '', $element_theme_2[0]); }else{ $element_theme_2[0] = str_replace("{cf_firstoptiondata}", '', $element_theme_2[0]); } } $ClearElements[] = $element_theme_2[0]; if($email_template){ $ClearElements_Email[] = $element_email_2[0]; } //$htmloutput .= $element_theme_2[0]; //$emailoutput .= $element_email_2[0]; } } return array('theme' => $ClearElements, 'email' => $ClearElements_Email, 'omitted' => $OmittedElements); } function transformChronoContact( $id, $option ){ global $mainframe; $database =& JFactory::getDBO(); $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".$id."'" ); $row = $database->loadObject(); if(!trim($row->chronocode)){ $mainframe->redirect( 'index2.php?option='.$option , "Sorry but this form was not created using the wizard"); } HTML_ChronoContact::transformChronoContact( $row, $option ); } function previewajaxChronoContact( $option ){ global $mainframe; $database =& JFactory::getDBO(); if(trim(JRequest::getVar('formid')) == ''){ echo 'Something went wrong, there is no form id posted!'; return; } $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".JRequest::getVar('formid')."'" ); $row = $database->loadObject(); if(trim(JRequest::getVar('theme')) == ''){ echo 'It looks like you didn\'t select a theme!!'; return; } ?> chronocode; $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode); $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode); //echo $XHTMLELEMENTS[0]; $htmlcode = ''; $htmloutput = ''; //load theme ob_start(); require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.trim(JRequest::getVar('theme')).DS."elements.php"); $theme_elements = ob_get_clean(); foreach($XHTMLELEMENTS as $XHTMLELEMENT){ if(trim($XHTMLELEMENT)){ $element_pieces = explode(CPHP_EOL, $XHTMLELEMENT); $thiselement = array(); $counter = 0; foreach($element_pieces as $element_piece){ if(($element_piece != '{')&&($element_piece != '}')&&($counter > 0)){ $linepieces = explode(" = ", $element_piece); if(count($linepieces) == 2){ $thiselement[trim($linepieces[0])] = $linepieces[1]; }else{ $thiselement[trim($linepieces[0])] = ''; } } $counter++; } if(($element_pieces[0] == '[type="cf_datetimepicker"')){ ?> close(); //return; } function savetransformChronoContact( $option ){ global $mainframe; $database =& JFactory::getDBO(); if(trim(JRequest::getVar('formid')) == ''){ $mainframe->redirect( "index2.php?option=$option", 'Something went wrong, there is no form id posted!'); } $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".JRequest::getVar('formid')."'" ); $row = $database->loadObject(); if(trim(JRequest::getVar('theme')) == ''){ $mainframe->redirect( "index2.php?option=$option", 'It looks like you didn\'t select a theme!!'); } define('CPHP_EOL', "\n"); $old_chrono_code = $row->chronocode; $row->chronocode = str_replace('CHRONO_CONSTANT_EOL', CPHP_EOL, $row->chronocode); $XHTMLELEMENTS = explode("}]".CPHP_EOL, $row->chronocode); //echo $XHTMLELEMENTS[0]; $htmlcode = ''; $htmloutput = ''; //load theme ob_start(); require_once(JPATH_SITE.DS."administrator".DS."components".DS."com_chronocontact".DS."themes".DS.trim(JRequest::getVar('theme')).DS."elements.php"); $theme_elements = ob_get_clean(); $WizardOutput = GetWizardOutput($XHTMLELEMENTS, $theme_elements, ''); $OmittedElements = $WizardOutput['omitted']; foreach($OmittedElements as $OmittedElement){ $WizardOutput['theme'][$OmittedElement] = ''; } $htmloutput = implode('', $WizardOutput['theme']); //$emailoutput = implode('', $WizardOutput['email']); $saverow =& JTable::getInstance('chronocontact', 'Table'); $database->setQuery( "SELECT * FROM #__chrono_contact WHERE id='".JRequest::getVar('formid')."'" ); $post = $database->loadAssoc(); if (!$saverow->bind( $post )) { JError::raiseWarning(100, $saverow->getError()); $mainframe->redirect( "index2.php?option=$option" ); } $saverow->html = $htmloutput; $saverow->theme = trim(JRequest::getVar('theme')); //end auto transform if (!$saverow->store()) { JError::raiseWarning(100, $saverow->getError()); $mainframe->redirect( "index2.php?option=$option" ); }else{ $mainframe->redirect( "index2.php?option=".$option, 'Form was Successfully transformed!'); } /* $database->setQuery( "UPDATE #__chrono_contact SET html='".$htmloutput."', theme='".trim(JRequest::getVar('theme'))."' WHERE id='".JRequest::getVar('formid')."'"); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); $mainframe->redirect( "index2.php?option=".$option ); }else{ $mainframe->redirect( "index2.php?option=".$option, 'Form was Successfully transformed!'); } */ } function wizard_elements( $option ){ global $mainframe; $limit = JRequest::getVar('limit', $mainframe->getCfg('list_limit')); $limitstart = JRequest::getVar('limitstart', 0); // count entries $database =& JFactory::getDBO(); $database->setQuery( "SELECT count(*) FROM #__chrono_contact_elements" ); $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_elements 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::wizard_elements( $rows, $pageNav, $option ); } function editElement( $id, $option ) { $database =& JFactory::getDBO(); $row =& JTable::getInstance('chronocontactelements', 'Table'); $row->load($id); HTML_ChronoContact::editElement( $row, $option ); } function saveElement( $task, $option ){ global $mainframe; $database =& JFactory::getDBO(); $row =& JTable::getInstance('chronocontactelements', 'Table'); $post = JRequest::get( 'post' , JREQUEST_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"; } $row->params = implode( "\n", $txt ); } if (!$row->store()) { JError::raiseWarning(100, $row->getError()); $mainframe->redirect( "index2.php?option=$option&task=tabs" ); } if($task == 'applyelement'){ editElement( $row->id, $option ); }else{ $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" ); } } function cancelElement( $option ) { global $mainframe; $database =& JFactory::getDBO(); $row =& JTable::getInstance('chronocontactelements', 'Table'); $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" ); } function deleteElement( $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&task=wizard_elements" ); } $cids = implode( ',', $cid ); $database->setQuery( "DELETE FROM #__chrono_contact_elements WHERE id IN ($cids)" ); if (!$database->query()) { JError::raiseWarning(100, $database->getErrorMsg()); $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" ); } $mainframe->redirect( "index2.php?option=$option&task=wizard_elements" ); } function generateAutoEmailTemplate($htmlcode){ global $mainframe; $database =& JFactory::getDBO(); ob_start(); eval( "?>".$htmlcode); $html_string = ob_get_clean(); $usednames = array(); //end fields names //text fields $pattern_input = '/]*?)type=("|\')(text|password|hidden|file)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ( $matches[0] as $match ) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (trim(str_replace('[]', '', $matches_name[2]))){ $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}"; if(!in_array($email_data_name, $usednames)){ $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; }else{ $html_string = str_replace($match, "", $html_string); } }else{ $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); } } //buttons $pattern_input = '/]*?)type=("|\')(submit|button|reset|image)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ( $matches[0] as $match ) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (trim(str_replace('[]', '', $matches_name[2]))){ $email_data_name = ""; if(!in_array($email_data_name, $usednames)){ $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; }else{ $html_string = str_replace($match, "", $html_string); } }else{ $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); } } //checkboxes or radios fields $pattern_input = '/]*?)type=("|\')(checkbox|radio)("|\')([^>]*?)>/is'; $matches = array(); $check_radio_idslist = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ($matches[0] as $match) { $pattern_id = '/id=("|\')([^(>|"|\')]*?)("|\')/i'; $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); preg_match($pattern_id, $match, $matches_id); if (trim(str_replace('[]', '', $matches_name[2]))){ $check_radio_idslist[] = $matches_id[2]; $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}"; if(!in_array($email_data_name, $usednames)){ $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; }else{ $html_string = str_replace($match, "", $html_string); } }else{ $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); } } //radios-checks labels $pattern_label = '/]*?)for=("|\')('.implode("|", $check_radio_idslist).')("|\')([^>]*?)>(.*?)<\/label>/is'; $matches = array(); preg_match_all($pattern_label, $html_string, $matches); foreach ( $matches[0] as $match ) { $html_string = str_replace($match, "", $html_string); } //textarea fields $pattern_textarea = '/]*?)>(.*?)<\/textarea>/is'; $matches = array(); preg_match_all($pattern_textarea, $html_string, $matches); $namematch = ''; foreach ( $matches[0] as $match ) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (trim(str_replace('[]', '', $matches_name[2]))){ $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}"; if(!in_array($email_data_name, $usednames)){ $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; }else{ $html_string = str_replace($match, "", $html_string); } }else{ $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); } } //select boxes $pattern_select = '//is'; $matches = array(); preg_match_all($pattern_select, $html_string, $matches); foreach ($matches[0] as $match) { $selectmatch = $match; $pattern_select2 = '/]*?)>/is'; preg_match_all($pattern_select2, $match, $matches2); $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $matches2[0][0], $matches_name); if (trim(str_replace('[]', '', $matches_name[2]))){ $email_data_name = "{".str_replace('[]', '', $matches_name[2])."}"; if(!in_array($email_data_name, $usednames)){ $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; }else{ $html_string = str_replace($match, "", $html_string); } }else{ $html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); } } return $html_string; } function generateFieldsNamesTypes($htmlcode){ global $mainframe; $database =& JFactory::getDBO(); ob_start(); eval( "?>".$htmlcode); $html_string = ob_get_clean(); $fieldsnames = array(); $fieldstypes = array(); //text fields $pattern_input = '/]*?)type=("|\')(text|password|hidden|file|checkbox|radio)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ( $matches[0] as $match ) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; $pattern_type = '/type=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); preg_match($pattern_type, $match, $matches_type); if (trim(str_replace('[]', '', $matches_name[2])) && !in_array(trim(str_replace('[]', '', $matches_name[2])), $fieldsnames)){ $fieldsnames[] = str_replace('[]', '', $matches_name[2]); if ($matches_type[2]){ $fieldstypes[] = $matches_type[2]; } } } //textarea fields $pattern_textarea = '/]*?)>(.*?)<\/textarea>/is'; $matches = array(); preg_match_all($pattern_textarea, $html_string, $matches); foreach ( $matches[0] as $match ) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (trim(str_replace('[]', '', $matches_name[2])) && !in_array(trim(str_replace('[]', '', $matches_name[2])), $fieldsnames)){ $fieldsnames[] = str_replace('[]', '', $matches_name[2]); $fieldstypes[] = "textarea"; } } //select boxes $pattern_select = '//is'; $matches = array(); preg_match_all($pattern_select, $html_string, $matches); foreach ($matches[0] as $match) { $selectmatch = $match; $pattern_select2 = '/]*?)>/is'; preg_match_all($pattern_select2, $match, $matches2); $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $matches2[0][0], $matches_name); if (trim(str_replace('[]', '', $matches_name[2])) && !in_array(trim(str_replace('[]', '', $matches_name[2])), $fieldsnames)){ $fieldsnames[] = str_replace('[]', '', $matches_name[2]); $fieldstypes[] = "select"; } } return array("names" => $fieldsnames, "types" => $fieldstypes); } ?>