bug fixins (#1951)
[openemr.git] / interface / super / layout_listitems_ajax.php
blob926319f738a2eb54e3453416626d410b6fc11f9e
1 <?php
2 /**
3 * Copyright (C) 2014-2016 Rod Roark <rod@sunsetsystems.com>
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
16 * @package OpenEMR
17 * @author Rod Roark <rod@sunsetsystems.com>
18 * @link http://www.open-emr.org
21 // Given a list ID, name of a target form field and a default value, this creates
22 // JavaScript that will write Option values into the target selection list.
27 require_once("../globals.php");
29 //verify csrf
30 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
31 csrfNotVerified();
34 $listid = $_GET['listid'];
35 $target = $_GET['target'];
36 $current = $_GET['current'];
38 $res = sqlStatement("SELECT option_id FROM list_options WHERE list_id = ? AND activity = 1 " .
39 "ORDER BY seq, option_id", array($listid));
41 echo "var itemsel = document.forms[0]['$target'];\n";
42 echo "var j = 0;\n";
43 echo "itemsel.options[j++] = new Option('-- " . xls('Please Select') . " --','',false,false);\n";
44 while ($row = sqlFetchArray($res)) {
45 $tmp = addslashes($row['option_id']);
46 $def = $row['option_id'] == $current ? 'true' : 'false';
47 echo "itemsel.options[j++] = new Option('$tmp','$tmp',$def,$def);\n";