When i do the modification, the results are not saved in the database

Any solution ?
Thanks.
<?php
/**
* Ckforms for CK Forms Component
*
* @package CK.Joomla
* @subpackage Components
* @link http://cookex.eu
* @license GNU/GPL
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
jimport( 'joomla.application.component.model' );
/**
* Ckforms Model
*
* @package CK.Joomla
* @subpackage Components
*/
class CkformsModelCkforms extends JModel {
var $_data;
/**
* Retrieves the form data
* @return array Array of objects containing the data from the database
*/
function getData() {
$array = JRequest::getVar('id', 0, '', 'array');
$id=(int)$array[0];
$query = 'SELECT * FROM #__ckforms where id=' . $id;
$this->_db->setQuery( $query );
$this->_data = $this->_db->loadObject();
$query = 'SELECT * FROM #__ckfields where fid='.$id." and published=1 order by ordering asc";
$fields = $this->_getList( $query );
$n=count($fields );
for ($i=0; $i < $n; $i++) {
// Fetch all values
$attribs = self::getAttr($fields[$i]->defaultvalue);
switch ($fields[$i]->typefield)
{
case 'text':
$fields[$i]->t_initvalueT = ( isset($attribs['t_initvalueT']) ? $attribs['t_initvalueT'] : '');
$fields[$i]->t_maxchar = ( isset($attribs['t_maxchar']) ? $attribs['t_maxchar'] : '');
$fields[$i]->t_texttype = ( isset($attribs['t_texttype']) ? $attribs['t_texttype'] : '');
$fields[$i]->t_minchar = ( isset($attribs['t_minchar']) ? $attribs['t_minchar'] : '');
break;
case 'hidden':
$fields[$i]->t_initvalueH = ( isset($attribs['t_initvalueH']) ? $attribs['t_initvalueH'] : '');
$fields[$i]->t_filluid = ( isset($attribs['t_filluid']) ? $attribs['t_filluid'] : '');
break;
case 'textarea':
$fields[$i]->t_initvalueTA = ( isset($attribs['t_initvalueTA']) ? $attribs['t_initvalueTA'] : '');
$fields[$i]->t_HTMLEditor = ( isset($attribs['t_HTMLEditor']) ? $attribs['t_HTMLEditor'] : '');
$fields[$i]->t_columns = ( isset($attribs['t_columns']) ? $attribs['t_columns'] : '');
$fields[$i]->t_rows = ( isset($attribs['t_rows']) ? $attribs['t_rows'] : '');
$fields[$i]->t_wrap = ( isset($attribs['t_wrap']) ? $attribs['t_wrap'] : '');
$fields[$i]->t_maxchar = ( isset($attribs['t_maxchar']) ? $attribs['t_maxchar'] : '');
$fields[$i]->t_minchar = ( isset($attribs['t_minchar']) ? $attribs['t_minchar'] : '');
break;
case 'checkbox':
$fields[$i]->t_initvalueCB = ( isset($attribs['t_initvalueCB']) ? $attribs['t_initvalueCB'] : '');
$fields[$i]->t_checkedCB = ( isset($attribs['t_checkedCB']) ? $attribs['t_checkedCB'] : '');
break;
case 'radiobutton':
$fields[$i]->t_listHRB = ( isset($attribs['t_listHRB']) ? $attribs['t_listHRB'] : '');
$fields[$i]->t_displayRB = ( isset($attribs['t_displayRB']) ? $attribs['t_displayRB'] : '');
break;
case 'select':
$fields[$i]->t_multipleS = ( isset($attribs['t_multipleS']) ? $attribs['t_multipleS'] : '');
$fields[$i]->t_heightS = ( isset($attribs['t_heightS']) ? $attribs['t_heightS'] : '');
$fields[$i]->t_listHS = ( isset($attribs['t_listHS']) ? $attribs['t_listHS'] : '');
break;
case 'button':
$fields[$i]->t_typeBT = ( isset($attribs['t_typeBT']) ? $attribs['t_typeBT'] : '');
break;
}
}
$this->_data->fields = $fields;
return $this->_data;
}
/**
* Save Hits
* @return void
*/
function addHits() {
$dba =& JFactory::getDBO();
$ckform = $this->getData();
$query = " update #__ckforms set hits = ".($ckform->hits + 1). " where id = ".$ckform->id;
$dba->Execute($query);
}
/**
* Save data
* @return void
*/
function saveData($post) {
$ckform = $this->getData();
// Handle uploaded files
if (file_exists ($ckform->uploadpath) == true) {
$nb_uploaded_file = 0;
$n=count($ckform->fields );
// Loop over all fields to find the uploads
for ($i=0; $i < $n; $i++) {
$field = $ckform->fields[$i];
if ($field->typefield == 'fileupload') {
// Found an uploaded file
$target_fu_path = $ckform->uploadpath . basename($_FILES[$field->name]['name']);
if(move_uploaded_file($_FILES[$field->name]['tmp_name'], $target_fu_path)) {
$uploaded_file[$nb_uploaded_file] = $target_fu_path;
$nb_uploaded_file++;
}
}
}
}
if ($ckform->saveresult == 1)
{
$dba =& JFactory::getDBO();
$query = ' insert into #__ckforms_'.$ckform->id."(" ;
$query2 = ' insert into #__ckforms_'.$ckform->id."(" ;
$n=count($ckform->fields );
for ($i=0; $i < $n; $i++)
{
$field = $ckform->fields[$i];
$query = $query."F".$field->id.",";
$query2 = $query2.$field->name.",";
}
$query = $query."created,ipaddress,published) values(";
$query2 = $query2."created,ipaddress,published) values(";
$n=count($ckform->fields );
for ($i=0; $i < $n; $i++)
{
$field = $ckform->fields[$i];
if ($field->typefield == 'fileupload' && isset($_FILES[$field->name]['name']) && $_FILES[$field->name]['name'] !='' )
{
$PathInf = pathinfo($_FILES[$field->name]['name']);
$ext = $PathInf['extension'];
$file = basename($_FILES[$field->name]['name'],".".$ext) . "_" . $fileuid . "." . $ext;
$fieldValue = $ckform->uploadpath . $file;
} else if (Isset($post[$field->name])){
$fieldValue = $post[$field->name];
} else {
$fieldValue = '';
}
if (is_array ($fieldValue))
{
$arrayVal = "";
foreach($fieldValue as $selectValue){
$arrayVal = $arrayVal.$selectValue.",";
}
if (strcasecmp(substr($arrayVal, strlen($arrayVal) - strlen(",")),",") == 0)
{
$arrayVal = substr($arrayVal, 0,strlen($arrayVal) - strlen(","));
}
$fieldValue = $arrayVal;
}
$query = $query."'".addslashes($fieldValue)."',";
$query2 = $query2."'".addslashes($fieldValue)."',";
}
$query = $query."'".date("Y-m-d H:i:s")."','".$_SERVER['REMOTE_ADDR']."',1)";
$query2 = $query2."'".date("Y-m-d H:i:s")."','".$_SERVER['REMOTE_ADDR']."',1)";
if (!$dba->Execute($query))
{
$errMsg = JText::_( 'Problem with' )." (".$query.")"."<br />". $dba->getErrorMsg();
if (!$dba->Execute($query2))
{
echo JText::_( 'Problem with' )." (".$query2.")";
echo $dba->getErrorMsg();
echo $errMsg;
}
//echo $query;
//die;
}
}
/* ************************* */
/* Send Email Result */
/* ************************* */
if ($ckform->emailresult == 1) {
$mail =& JFactory::getMailer();
$mail->CharSet = "utf-8";
$mailBody = "Form : ".$ckform->title." [".$ckform->name."]<br/>\n";
$mailBody = $mailBody."registered at ".date("Y-m-d H:i:s")."<br/><br/>\n\n";
$n=count($ckform->fields);
// Loop over all fields to include them in the mail
for ($i=0; $i < $n; $i++) {
// Grab the field by index
$field = $ckform->fields[$i];
// Load the value if it exists
$fieldValue = (isset($post[$field->name]) ? $post[$field->name] : '');
// Convert arrays to CSV
if (is_array($fieldValue)) $fieldValue = implode(',', $fieldValue);
// If this is a mail value, convert it into a link
if ($field->typefield == 'text')
if (self::getAttr($field->defaultvalue, 't_texttype') == 'email')
$fieldValue = '<a href="mailto:'.$fieldValue.'">'.$fieldValue.'</a>';
$mailBody .= $field->name . " : " . $fieldValue . "<br/>\n";
}
$mailBody .= JText::_( 'IP Address' ) . " : " . $_SERVER['REMOTE_ADDR'] . "<br/>\n";
// Add the mail targets, explode CSV into arrays
if ($ckform->emailto != "")
$mail->addRecipient( explode(",", $ckform->emailto) );
if ($ckform->emailcc != "")
$mail->addCC( explode(",", $ckform->emailcc) );
if ($ckform->emailbcc != 0)
$mail->addBCC( explode(",", $ckform->emailbcc) );
// Set other info
$mail->setSender( array( $ckform->emailfrom, "" ) );
$mail->setSubject( $ckform->subject );
$mail->setBody( $mailBody );
$mail->IsHTML (true);
// Add attachments if desired
if (Isset($nb_uploaded_file) && $ckform->emailresultincfile == "1")
for ($i=0; $i < $nb_uploaded_file; $i++)
$mail->addAttachment($uploaded_file[$i]);
$sent = $mail->Send();
}
/* ************************** */
/* Send Email Receipt */
/* ************************** */
if ($ckform->emailreceipt == 1) {
$IsSendMail = false;
$emailReceiptTo = '';
$mail =& JFactory::getMailer();
$mail->CharSet = "utf-8";
$mailBody = $ckform->emailreceipttext;
$formData = 'Form: {ckforms_title}<br/>\n';
$formData .= 'Date: {ckforms_date}<br/>\n';
$formData .= JText::_( 'IP Address' ) . " : {ckforms_ip}<br/><br/>\n";
$n = count($ckform->fields);
// Iterate of all fields to find the first email field and add each field to the form dump
for ($i=0; $i < $n; $i++) {
$field = $ckform->fields[$i];
if ($field->typefield == 'text') {
$type = self::getAttr($field->defaultvalue, 't_texttype');
if($type == 'email') {
$IsSendMail = true;
$emailReceiptTo = $post[$field->name];
}
}
// Now add it to the form dump, note that we do not yet insert the value here
$formData .= $field->name . ": {" . $field->name . "}<br/>\n";
}
// Start substitution by checking if we want the form dump in the first place, if so, append to message
if ($ckform->emailreceiptincfield == 1)
$mailBody .= $formData;
// Loop over all fields to insert all values
for ($i=0; $i < $n; $i++) {
$field = $ckform->fields[$i];
// See if we have a value for this field
$fieldValue = (isset($post[$field->name]) ? $post[$field->name] : '');
// If it is an array, make it a comma seperated list
if (is_array ($fieldValue)) $fieldValue = implode(',', $fieldValue);
// Now replace the value markers by their value
$mailBody = str_replace('{'.$field->name.'}', $fieldValue, $mailBody);
}
// Replace the generated fields: ckforms_title, ckforms_ip and ckforms_date
$mailBody = str_replace('{ckforms_title}', $ckform->title, $mailBody);
$mailBody = str_replace('{ckforms_date}', date("Y-m-d H:i:s"), $mailBody);
$mailBody = str_replace('{ckforms_ip}', $_SERVER['REMOTE_ADDR'], $mailBody);
// Add attachements if desired
if (isset($nb_uploaded_file) && $ckform->emailreceiptincfile == "1")
for ($i=0; $i < $nb_uploaded_file; $i++)
$mail->addAttachment($uploaded_file[$i]);
// Check if we have a recipient and we still want to send the mail
if ($emailReceiptTo != "" && $IsSendMail == true) {
$mail->addRecipient($emailReceiptTo);
$mail->setSender( array( $ckform->emailfrom, "" ) );
$mail->setSubject( $ckform->emailreceiptsubject );
$mail->setBody( $mailBody );
$mail->IsHTML (true);
$sent = $mail->Send();
}
}
}
/**
* Extract a named attribute from the given raw string. The format is:
* t_initvalueT===[--]t_maxchar===128[--]t_texttype===email[--]t_minchar===6
*
* Returns null when a value is not found or an empty string when its empty.
*
* If no name is given (name == null) the complete array of name and value pairs will be returned as an array
*/
static function getAttr($raw, $attributeName = null) {
if(!is_string($raw) || trim($raw) == '') return '';
// The following regular expression cuts out all attribute name and value pairs
$reg = "/([A-Za-z_]+)===([^\[]*)/";
// Regex the values out, note that the m array will hold the following sub arrays:
// 0: Full pattern match
// 1: First subpattern match aka the names
// 2: Second subpattern match aka the values
if (preg_match_all($reg, $raw, $m) !== false) {
// Test if we have a name
if (is_null($attributeName)) {
// Return the full result
return array_combine($m[1], $m[2]);
}
// Fetch the index of the given name in the results
$id = array_search($attributeName, $m[1]);
if($id === false) return null;
// Found it, return the value
return $m[2][$id];
} else {
// Something went wrong parsing the string
return null;
}
}
}
Users browsing this forum: No registered users and 0 guests