Contributed GYM Forms, some of the table.sql files include inserts into list_options...
[openemr.git] / contrib / forms / pelvic_soap / save.php
blob3f892ae0e74aa9cef78fa200b0f84ad49d7fbd3c
1 <?php
2 /* this page is intended to be the 'action=' target of a form object.
3 * it is called to save the contents of the form into the database
4 */
6 /* for $GLOBALS[], ?? */
7 require_once('../../globals.php');
8 /* for acl_check(), ?? */
9 require_once($GLOBALS['srcdir'].'/api.inc');
10 /* for ??? */
11 require_once($GLOBALS['srcdir'].'/forms.inc');
12 /* for formDataCore() */
13 require_once($GLOBALS['srcdir'].'/formdata.inc.php');
15 /** CHANGE THIS - name of the database table associated with this form **/
16 $table_name = 'form_pelvic_soap';
18 /** CHANGE THIS name to the name of your form. **/
19 $form_name = 'POP';
21 /** CHANGE THIS to match the folder you created for this form. **/
22 $form_folder = 'pelvic_soap';
24 /* Check the access control lists to ensure permissions to this page */
25 $thisauth = acl_check('patients', 'med');
26 if (!$thisauth) {
27 die($form_name.': Access Denied.');
29 /* perform a squad check for pages touching patients, if we're in 'athletic team' mode */
30 if ($GLOBALS['athletic_team']!='false') {
31 $tmp = getPatientData($pid, 'squad');
32 if ($tmp['squad'] && ! acl_check('squads', $tmp['squad']))
33 $thisauth = 0;
36 /* an array of all of the fields' names and their types. */
37 $field_names = array('pelvic_complaints' => 'checkbox_combo_list','pelvic_exam' => 'checkbox_combo_list','pelvic_assessment' => 'checkbox_combo_list','pelvic_plan' => 'checkbox_combo_list','plan_discussion' => 'textarea');
38 /* an array of the lists the fields may draw on. */
39 $lists = array('pelvic_complaints' => 'Pelvic_Complaints', 'pelvic_exam' => 'Pelvic_Exam', 'pelvic_assessment' => 'Pelvic_Assessment', 'pelvic_plan' => 'Pelvic_Plan');
41 /* get each field from $_POST[], storing them into $field_names associated with their names. */
42 foreach($field_names as $key=>$val)
44 $pos = '';
45 $neg = '';
46 if ($val == 'textbox' || $val == 'textarea' || $val == 'provider' || $val == 'textfield')
48 $field_names[$key]=$_POST['form_'.$key];
50 if ($val == 'date')
52 $field_names[$key]=$_POST[$key];
54 if (($val == 'checkbox_list' ))
56 $field_names[$key]='';
57 if (isset($_POST['form_'.$key]) && $_POST['form_'.$key] != 'none' ) /* if the form submitted some entries selected in that field */
59 $lres=sqlStatement("select * from list_options where list_id = '".$lists[$key]."' ORDER BY seq, title");
60 while ($lrow = sqlFetchArray($lres))
62 if (is_array($_POST['form_'.$key]))
64 if ($_POST['form_'.$key][$lrow[option_id]])
66 if ($field_names[$key] != '')
67 $field_names[$key]=$field_names[$key].'|';
68 $field_names[$key] = $field_names[$key].$lrow[option_id];
74 if (($val == 'checkbox_combo_list'))
76 $field_names[$key]='';
77 if (isset($_POST['check_'.$key]) && $_POST['check_'.$key] != 'none' ) /* if the form submitted some entries selected in that field */
79 $lres=sqlStatement("select * from list_options where list_id = '".$lists[$key]."' ORDER BY seq, title");
80 while ($lrow = sqlFetchArray($lres))
82 if (is_array($_POST['check_'.$key]))
84 if ($_POST['check_'.$key][$lrow[option_id]])
86 if ($field_names[$key] != '')
87 $field_names[$key]=$field_names[$key].'|';
88 $field_names[$key] = $field_names[$key].$lrow[option_id].":xx".$_POST['form_'.$key][$lrow[option_id]];
94 if (($val == 'dropdown_list'))
96 $field_names[$key]='';
97 if (isset($_POST['form_'.$key]) && $_POST['form_'.$key] != 'none' ) /* if the form submitted some entries selected in that field */
99 $lres=sqlStatement("select * from list_options where list_id = '".$lists[$key]."' ORDER BY seq, title");
100 while ($lrow = sqlFetchArray($lres))
102 if ($_POST['form_'.$key] == $lrow[option_id])
104 $field_names[$key]=$lrow[option_id];
105 break;
112 /* at this point, field_names[] contains an array of name->value pairs of the fields we expected from the form. */
114 /* escape form data for entry to the database. */
115 foreach ($field_names as $k => $var) {
116 $field_names[$k] = formDataCore($var);
119 if ($encounter == '') $encounter = date('Ymd');
121 if ($_GET['mode'] == 'new') {
122 /* NOTE - for customization you can replace $_POST with your own array
123 * of key=>value pairs where 'key' is the table field name and
124 * 'value' is whatever it should be set to
125 * ex) $newrecord['parent_sig'] = $_POST['sig'];
126 * $newid = formSubmit($table_name, $newrecord, $_GET['id'], $userauthorized);
129 /* make sure we're at the beginning of the array */
130 reset($field_names);
132 /* save the data into the form's encounter-based table */
133 $newid = formSubmit($table_name, $field_names, $_GET['id'], $userauthorized);
134 /* link this form into the encounter. */
135 addForm($encounter, $form_name, $newid, $form_folder, $pid, $userauthorized);
138 elseif ($_GET['mode'] == 'update') {
139 /* make sure we're at the beginning of the array */
140 reset($field_names);
142 /* update the data in the form's table */
143 $success = formUpdate($table_name, $field_names, $_GET['id'], $userauthorized);
144 /* sqlInsert('update '.$table_name." set pid = {".$_SESSION['pid']."},groupname='".$_SESSION['authProvider']."',user='".$_SESSION['authUser']."',authorized=$userauthorized,activity=1,date = NOW(), where id=$id"); */
148 $_SESSION['encounter'] = $encounter;
150 formHeader('Redirecting....');
151 /* defaults to the encounters page. */
152 formJump();
154 formFooter();