cravaus wrote on Tuesday, November 03, 2015:
I am in the process of modifying the CMS Portal to work with CF7 rather than Ninja Forms. I have made some progresss and am hitting a wall, so perhaps someone can point me in the right direction.
What is Required:
In /openemr/interface/cmsportal/upload_form.php line 46 I changed intval to floatval:
$postid = empty($_REQUEST[‘postid’ ]) ? 0 : floatval($_REQUEST[‘postid’ ]);
In WordPress
Contact Form 7 plugin
Contact Form DB plugin (currently configured to just work with CF7)
Forms must be made in CF7 with fields that match openemr fields. I just copied from Rod’s Jinja Forms.
In wordpress/wp-content/plugins/sunset-patient-portal/webserve.php
I deleted the following lines 14-24
$tmp = $wpdb->prefix . "nf_objects";
$tmp2 = $wpdb->prefix . "ninja_forms";
if($wpdb->get_var("SHOW TABLES LIKE '$tmp2'") != $tmp2) {
define('FORMS_METHOD', 'NINJA3');
}
else if($wpdb->get_var("SHOW TABLES LIKE '$tmp'") == $tmp) {
define('FORMS_METHOD', 'NINJA2');
}
else {
define('FORMS_METHOD', 'NINJA');
}
I modified the action_list function replacing all the Ninja Forms code with this:
function action_list($date_from='', $date_to='') {
global $wpdb, $out, $admin_user_login;
$out['list'] = array();
$out['messages'] = array();
date_default_timezone_set('UTC');
$from_date=strtotime($date_from." 00:00:00");
$to_date=strtotime($date_to." 23:59:59");
$query =
"SELECT submit_time, field_value, form_name " .
"FROM {$wpdb->prefix}cf7dbplugin_submits " .
"WHERE field_order = 9999";
$qparms = array();
if ($date_from) {
$query .= " AND submit_time >= %d";
$qparms[] = "$from_date";
}
if ($date_to) {
$query .= " AND submit_time <= %d";
$qparms[] = "$to_date";
}
$query .= " ORDER BY submit_time";
$query = $wpdb->prepare($query, $qparms);
if (empty($query)) {
$out['errmsg'] = "Internal error: wpdb prepare() failed.";
return;
}
$rows = $wpdb->get_results($query, ARRAY_A);
foreach ($rows as $row) {
$out['list'][] = array(
'postid' => $row['submit_time'],
'user' => (isset($row['field_value']) ? $row['field_value'] : ''),
'datetime' => gmdate("Y-m-d H:i:s",$row['submit_time']),
'type' => $row['form_name'],
);
}
This works.
I did not touch the messaging code.
Now I am working on the action_getpost function. Again deleting all the Ninja code. This is not complete but much of it works:
function action_getpost($postid) {
global $wpdb, $out;
$out['post'] = array();
$out['uploads'] = array();
// wp_posts has one row for each submitted form.
// wp_nf_objectmeta includes a set of rows for each defined form.
$query =
"SELECT submit_time, form_name, field_value " .
"FROM {$wpdb->prefix}cf7dbplugin_submits " .
"WHERE field_order = 9999 AND submit_time = %f";
$queryp = $wpdb->prepare($query, $postid);
if (empty($queryp)) {
$out['errmsg'] = "Internal error: \"$query\" \"$postid\"";
return;
}
$row = $wpdb->get_row($queryp, ARRAY_A);
if (empty($row)) {
$out['errmsg'] = "No rows matching: \"$postid\"";
echo $queryp;
return;
}
$formid = $row['submit_time'];
$out['post'] = array(
'postid' => $row['submit_time'],
'user' => (isset($row['field_value']) ? $row['field_value'] : ''),
'datetime' => gmdate("Y-m-d H:i:s",$row['submit_time']),
'type' => $row['form_name'],
);
$out['fields'] = array();
$out['labels'] = array();
This all works. The following is not working, field names are not interpreted–
// wp_cf7dbplugin_submits has one row for each defined form field.
$query2 =
"SELECT field_name, field_value " .
"FROM {$wpdb->prefix}cf7dbplugin_submits " .
"WHERE field_order < 9999 AND submit_time= %f " .
"ORDER BY field_order ";
$query2p = $wpdb->prepare($query2, $postid);
$rows = $wpdb->get_results($query2p, ARRAY_A);
foreach ($rows as $fldrow) {
$flddata = unserialize($fldrow['field_name']);
// Report uploads, if any.
if (isset($flddata['upload_location']) && !empty($fldrow['field_value'])) {
$selval = unserialize($fldrow['field_value']);
if (is_array($selval)) { // should always be true
foreach ($selval as $uparr) {
if (empty($uparr['upload_id'])) continue;
$filepath = $uparr['file_path'] . $uparr['file_name'];
// Put the info into the uploads array.
$out['uploads'][] = array(
'filename' => $uparr['user_file_name'],
'mimetype' => get_mime_type($filepath),
'id' => $uparr['upload_id'],
);
}
}
}
// Each field that matches with a field name in OpenEMR must have that name in
// its description text. Normally this is in the form of an HTML comment at the
// beginning of this text, e.g. "<!-- field_name -->". The regular expression
// below picks out the name as the first "word" of the description.
if (!preg_match('/([a-zA-Z0-9_:]+)/', $flddata['desc_text'], $matches)) continue;
$fldname = $matches[1];
if (is_string($fldrow['field_value'])) {
// Ninja perversely stores values encoded for HTML output.
$out['fields'][$fldname] = htmlspecialchars_decode($fldrow['field_value'], ENT_QUOTES | ENT_HTML401);
}
else {
$out['fields'][$fldname] = $fldrow['field_value'];
}
$out['labels'][$fldname] = $flddata['label'];
}
}
I know Rod is stripping out all the extra stuff that Ninja puts in their fields (what a mess). Much of this is not necessary. I am not sure what to take out and what to leave in. The CF7 table is very simple. My Query produces this simple data set:
field_name field_value
lname Lasname
fname Firstname
mname Middlename
email email@emailaddress.com
sex Male
status Married
street 543 Street St.
city Mytown
state California
postal_code 92222
phone_home 9994446666
phone_biz 9994446666
phone_cell 9994446666
guardiansname Mom
contact_relationship Wife
phone_contact 9994446666
ref_providerID Referring Doctor
Much more simple than Ninja. But it is not processing as is. That is, the field names are not being interpreted. Any tips would be welcome. At the very least I think, htmlspecialchars_decode($fldrow[‘field_value’], ENT_QUOTES | ENT_HTML401); could go.