6464//
6565function getKittens ($ catid , $ catstring , &$ categories ) {
6666 $ cres = sqlStatement ("SELECT id, name FROM categories " .
67- "WHERE parent = $ catid ORDER BY name " );
67+ "WHERE parent = ? ORDER BY name " , array ( $ catid ) );
6868 $ childcount = 0 ;
6969 while ($ crow = sqlFetchArray ($ cres )) {
7070 ++$ childcount ;
@@ -88,7 +88,7 @@ function mergeTiffs() {
8888 $ inames .= ' ' . escapeshellarg ("$ inbase.tif " );
8989 }
9090 if (!$ inames ) die (xl ("Internal error - no pages were selected! " ));
91- $ tmp0 = exec ("cd ' $ faxcache' ; tiffcp $ inames temp.tif " , $ tmp1 , $ tmp2 );
91+ $ tmp0 = exec ("cd " . escapeshellarg ( $ faxcache) . " ; tiffcp $ inames temp.tif " , $ tmp1 , $ tmp2 );
9292 if ($ tmp2 ) {
9393 $ msg .= "tiffcp returned $ tmp2: $ tmp0 " ;
9494 }
@@ -107,7 +107,7 @@ function mergeTiffs() {
107107 if (!$ patient_id ) die (xl ('Internal error - patient ID was not provided! ' ));
108108 // Compute the name of the target directory and make sure it exists.
109109 $ docdir = $ GLOBALS ['OE_SITE_DIR ' ] . "/documents/ $ patient_id " ;
110- exec ("mkdir -p ' $ docdir' " );
110+ exec ("mkdir -p " . escapeshellarg ( $ docdir) );
111111
112112 // If copying to patient documents...
113113 //
@@ -134,7 +134,7 @@ function mergeTiffs() {
134134 $ info_msg .= mergeTiffs ();
135135 // The -j option here requires that libtiff is configured with libjpeg.
136136 // It could be omitted, but the output PDFs would then be quite large.
137- $ tmp0 = exec ("tiff2pdf -j -p letter -o ' $ target' ' $ faxcache/temp.tif' " , $ tmp1 , $ tmp2 );
137+ $ tmp0 = exec ("tiff2pdf -j -p letter -o " . escapeshellarg ( $ target) . " " . escapeshellarg ( $ faxcache . ' /temp.tif ') , $ tmp1 , $ tmp2 );
138138
139139 if ($ tmp2 ) {
140140 $ info_msg .= "tiff2pdf returned $ tmp2: $ tmp0 " ;
@@ -153,10 +153,8 @@ function mergeTiffs() {
153153 sqlStatement ($ query );
154154 $ query = "INSERT INTO categories_to_documents ( " .
155155 "category_id, document_id " .
156- " ) VALUES ( " .
157- "' $ catid', ' $ newid' " .
158- ") " ;
159- sqlStatement ($ query );
156+ " ) VALUES (?, ?) " ;
157+ sqlStatement ($ query , array ($ catid , $ newid ));
160158 } // end not error
161159
162160 // If we are posting a note...
@@ -203,24 +201,22 @@ function mergeTiffs() {
203201// scanned notes must be installed, and does not natively exist.
204202 $ query = "INSERT INTO form_scanned_notes ( " .
205203 "notes " .
206- ") VALUES ( " .
207- "' " . $ _POST ['form_copy_sn_comments ' ] . "' " .
208- ") " ;
209- $ formid = sqlInsert ($ query );
204+ ") VALUES (?) " ;
205+ $ formid = sqlInsert ($ query , array ($ _POST ['form_copy_sn_comments ' ]));
210206 addForm ($ encounter_id , "Scanned Notes " , $ formid , "scanned_notes " ,
211207 $ patient_id , $ userauthorized );
212208 //
213209 $ imagedir = $ GLOBALS ['OE_SITE_DIR ' ] . "/documents/ $ patient_id/encounters " ;
214210 $ imagepath = "$ imagedir/ $ {encounter_id}_ $ formid.jpg " ;
215211 if (! is_dir ($ imagedir )) {
216- $ tmp0 = exec ('mkdir -p " ' . $ imagedir . ' " ' , $ tmp1 , $ tmp2 );
212+ $ tmp0 = exec ('mkdir -p ' . escapeshellarg ( $ imagedir) , $ tmp1 , $ tmp2 );
217213 if ($ tmp2 ) die ("mkdir returned $ tmp2: $ tmp0 " );
218- exec ("touch ' $ imagedir/index.html' " );
214+ exec ("touch " . escapeshellarg ( $ imagedir . " /index.html " ) );
219215 }
220216 if (is_file ($ imagepath )) unlink ($ imagepath );
221217 // TBD: There may be a faster way to create this file, given that
222218 // we already have a jpeg for each page in faxcache.
223- $ cmd = "convert -resize 800 -density 96 ' $ tmp_name' -append ' $ imagepath' " ;
219+ $ cmd = "convert -resize 800 -density 96 " . escapeshellarg ( $ tmp_name) . " -append " . escapeshellarg ( $ imagepath) ;
224220 $ tmp0 = exec ($ cmd , $ tmp1 , $ tmp2 );
225221 if ($ tmp2 ) die ("\"$ cmd \" returned $ tmp2: $ tmp0 " );
226222 }
@@ -271,17 +267,17 @@ function mergeTiffs() {
271267 $ cpstring = str_replace ('{MESSAGE} ' , $ form_message , $ cpstring );
272268 fwrite ($ tmph , $ cpstring );
273269 fclose ($ tmph );
274- $ tmp0 = exec ("cd $ webserver_root/custom; " . $ GLOBALS ['hylafax_enscript ' ] .
275- " -o $ tmpfn2 $ tmpfn1" , $ tmp1 , $ tmp2 );
270+ $ tmp0 = exec ("cd " . escapeshellarg ( $ webserver_root . ' /custom ' ) . " ; " . escapeshellcmd ( $ GLOBALS ['hylafax_enscript ' ]) .
271+ " -o " . escapeshellarg ( $ tmpfn2) . " " . escapeshellarg ( $ tmpfn1) , $ tmp1 , $ tmp2 );
276272 if ($ tmp2 ) {
277273 $ info_msg .= "enscript returned $ tmp2: $ tmp0 " ;
278274 }
279275 unlink ($ tmpfn1 );
280276
281277 // Send the fax as the cover page followed by the selected pages.
282278 $ info_msg .= mergeTiffs ();
283- $ tmp0 = exec ("sendfax -A -n $ form_finemode -d " .
284- escapeshellarg ($ form_fax ) . " $ tmpfn2 ' $ faxcache/temp.tif' " ,
279+ $ tmp0 = exec ("sendfax -A -n " . escapeshellarg ( $ form_finemode) . " -d " .
280+ escapeshellarg ($ form_fax ) . " " . escapeshellarg ( $ tmpfn2) . " " . escapeshellarg ( $ faxcache . ' /temp.tif ') ,
285281 $ tmp1 , $ tmp2 );
286282 if ($ tmp2 ) {
287283 $ info_msg .= "sendfax returned $ tmp2: $ tmp0 " ;
@@ -356,21 +352,21 @@ function mergeTiffs() {
356352// This will contain a .tif image as well as a .jpg image for each page.
357353//
358354if (! is_dir ($ faxcache )) {
359- $ tmp0 = exec ('mkdir -p " ' . $ faxcache . ' " ' , $ tmp1 , $ tmp2 );
355+ $ tmp0 = exec ('mkdir -p ' . escapeshellarg ( $ faxcache) , $ tmp1 , $ tmp2 );
360356 if ($ tmp2 ) die ("mkdir returned $ tmp2: $ tmp0 " );
361357 if (strtolower ($ ext ) != '.tif ' ) {
362358 // convert's default density for PDF-to-TIFF conversion is 72 dpi which is
363359 // not very good, so we upgrade it to "fine mode" fax quality. It's really
364360 // better and faster if the scanner produces TIFFs instead of PDFs.
365- $ tmp0 = exec ("convert -density 203x196 ' $ filepath' ' $ faxcache/deleteme.tif' " , $ tmp1 , $ tmp2 );
361+ $ tmp0 = exec ("convert -density 203x196 " . escapeshellarg ( $ filepath) . " " . escapeshellarg ( $ faxcache . ' /deleteme.tif ') , $ tmp1 , $ tmp2 );
366362 if ($ tmp2 ) die ("convert returned $ tmp2: $ tmp0 " );
367- $ tmp0 = exec ("cd ' $ faxcache' ; tiffsplit 'deleteme.tif'; rm -f 'deleteme.tif' " , $ tmp1 , $ tmp2 );
363+ $ tmp0 = exec ("cd " . escapeshellarg ( $ faxcache) . " ; tiffsplit 'deleteme.tif'; rm -f 'deleteme.tif' " , $ tmp1 , $ tmp2 );
368364 if ($ tmp2 ) die ("tiffsplit/rm returned $ tmp2: $ tmp0 " );
369365 } else {
370- $ tmp0 = exec ("cd ' $ faxcache' ; tiffsplit ' $ filepath' " , $ tmp1 , $ tmp2 );
366+ $ tmp0 = exec ("cd " . escapeshellarg ( $ faxcache) . " ; tiffsplit " . escapeshellarg ( $ filepath) , $ tmp1 , $ tmp2 );
371367 if ($ tmp2 ) die ("tiffsplit returned $ tmp2: $ tmp0 " );
372368 }
373- $ tmp0 = exec ("cd ' $ faxcache' ; mogrify -resize 750x970 -format jpg *.tif " , $ tmp1 , $ tmp2 );
369+ $ tmp0 = exec ("cd " . escapeshellarg ( $ faxcache) . " ; mogrify -resize 750x970 -format jpg *.tif " , $ tmp1 , $ tmp2 );
374370 if ($ tmp2 ) die ("mogrify returned $ tmp2: $ tmp0; ext is ' $ ext'; filepath is ' $ filepath' " );
375371}
376372
0 commit comments