Assorted minor corrections per code review.
[openemr.git] / library / custom_template / add_template.php
blob3cce6678daa87f54df01daa3b0a72cd1d1bb15ea
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Jacob T Paul <jacob@zhservices.com>
26 // +------------------------------------------------------------------------------+
28 //SANITIZE ALL ESCAPES
29 $sanitize_all_escapes=true;
32 //STOP FAKE REGISTER GLOBALS
33 $fake_register_globals=false;
36 require_once("../../interface/globals.php");
37 $list_id = $_REQUEST['list_id'];
39 <html>
40 <head>
41 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
42 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
43 <script type="text/javascript">
44 function add_template(){
45 top.restoreSession();
46 mainform=window.parent.parent.document;
47 if(document.getElementById('template_name').value){
48 len = document.getElementById('multi_context').options.length;
49 sel_len=0;
50 val="";
51 for(i=0;i<len;i++){
52 if(document.getElementById('multi_context').options[i].selected==true){
53 sel_len++;
54 val+=document.getElementById('multi_context').options[i].value+"|";
57 if(sel_len>0){
58 $.ajax({
59 type: "POST",
60 url: "ajax_code.php",
61 dataType: "html",
62 data: {
63 templateid: document.getElementById('template_name').value,
64 list_id: <?php echo $list_id;?>,
65 multi: val,
66 source: "add_template"
68 async: false,
69 success: function(thedata){
70 if(thedata=="Fail"){
71 alert(document.getElementById('template_name').value+" <?php echo addslashes(xl('already exists'));?>");
72 return false;
74 else{
75 mainform.getElementById('templateDD').innerHTML = thedata;
76 alert("<?php echo addslashes(xl('Successfully added category'));?> "+document.getElementById('template_name').value);
77 window.parent.parent.location.reload();
80 error:function(){
83 });
85 else{
86 alert("<?php echo addslashes(xl('You should select at least one context'));?>");
89 else{
90 alert("<?php echo addslashes(xl('Category name is empty'));?>");
91 return false;
94 </script>
95 </head>
96 <body class="body_top">
97 <form >
98 <table>
99 <tr class="text">
100 <td>
101 <select multiple name="multi_context[]" id="multi_context" size="5">
102 <?php
103 $res = sqlStatement("SELECT * FROM customlists WHERE cl_list_type=2 AND cl_deleted=0");
104 while($row=sqlFetchArray($res)){
105 echo "<option value='".htmlspecialchars($row['cl_list_id'],ENT_QUOTES)."'>".htmlspecialchars($row['cl_list_item_long'],ENT_QUOTES)."</option>";
108 </select>
109 </td>
110 <td>
111 <input type="text" name="template_name" id="template_name">
112 </td>
113 <td>
114 <a href="#" onclick="add_template()" class="css_button"><span><?php echo htmlspecialchars(xl('ADD'),ENT_QUOTES);?></span></a>
115 </td>
116 </tr>
117 </table>
118 </form>
119 </body>
120 </html>