NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/PrintProduction/production.inc.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Print widget
4  *
5  * @project     CWC2
6  * @revision    $Id:
7  * @purpose     This page contains supporting php functions for the production
8  *              page.
9  * @author      William A. Bronsema, C.E.T. (bronsema@dmsolutions.ca)
10  * @copyright
11  * <b>Copyright (c) 2001, DM Solutions Group Inc.</b>
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  */
30
31 /*****************************************************************************
32  * $Log: production.inc.php,v $
33  * Revision 1.3  2004/11/16 15:23:40  pspencer
34  * bug MT 377: renamed PrintWidget to PrintProduction
35  *
36  * Revision 1.2  2004/04/28 13:43:14  pspencer
37  * fix file path related issues
38  *
39  * Revision 1.1  2004/04/23 16:51:44  pspencer
40  * moved production.inc.php to PrintProduction/production.inc.php
41  *
42  * Revision 1.14  2004/02/25 20:25:07  sfournier
43  * Change installer and make sure COMMON and WEBCOMMON is used everiwhere
44  *
45  * Revision 1.13  2003/10/27 20:46:19  sfournier
46  * Overwrite main branch with 1.1 stuff
47  *
48  * Revision 1.10.2.1  2003/10/15 21:04:57  pspencer
49  * fixes to work with Chameleon 1.1
50  *
51  * Revision 1.10  2003/04/08 20:09:58  sacha
52  * Fixed few bug related to print
53  *
54  * Revision 1.9  2003/01/30 13:49:58  sacha
55  * Changed the session management
56  *
57  * Revision 1.8  2003/01/07 20:25:08  bronsema
58  * Updated function header comments to the doxygen style
59  *
60  * Revision 1.7  2003/01/07 20:04:20  bronsema
61  * Included serveral misc settings
62  *
63  * Revision 1.6  2003/01/07 18:33:45  bronsema
64  * Added legend
65  *
66  * Revision 1.5  2003/01/03 18:51:01  bronsema
67  * Moved the download file capabiltiy to the production page.
68  *
69  * Revision 1.4  2002/12/13 19:42:19  bronsema
70  * Updated the print and production dialogs to new style.  Fixed neat line.
71  *
72  * Revision 1.3  2002/11/28 18:29:19  sacha
73  * Fixed path
74  *
75  * Revision 1.2  2002/11/28 04:14:33  pspencer
76  * removed code that caused notices
77  *
78  * Revision 1.1  2002/11/21 00:46:00  sacha
79  * added print widget
80  *
81  * Revision 1.15  2002/08/12 20:26:18  bronsema
82  * Added delayed drawing functionality to map production.
83  *
84  * Revision 1.14  2002/07/22 18:57:23  bronsema
85  * Fixed bug with displaying footer
86  *
87  * Revision 1.13  2002/07/11 19:23:28  bronsema
88  * Updated layout
89  *
90  * Revision 1.12  2002/07/11 16:07:48  bronsema
91  * Added ability to turn margins on and off
92  *
93  * Revision 1.11  2002/07/11 15:11:07  bronsema
94  * Updated the production page to default to the map widht and height.
95  *
96  * Revision 1.10  2002/07/11 14:37:41  bronsema
97  * Fixed projection issue in map production
98  *
99  * Revision 1.9  2002/07/10 03:34:56  bronsema
100  * Updated to handle invalid characters
101  *
102  * Revision 1.8  2002/07/10 00:39:15  bronsema
103  * Fixed foot note alignment problem
104  *
105  * Revision 1.7  2002/07/09 14:37:30  bronsema
106  * Added new print icon
107  *
108  * Revision 1.6  2002/07/09 14:10:19  bronsema
109  * Added north arrow symbols
110  *
111  * Revision 1.5  2002/07/05 02:22:46  bronsema
112  * Removed dependancy on register_globals setting to be on.
113  *
114  * Revision 1.4  2002/06/27 02:19:10  bronsema
115  * Finished translation
116  *
117  * Revision 1.3  2002/06/26 03:24:03  bronsema
118  * Added map production
119  *
120  * Revision 1.2  2002/06/26 00:02:50  bronsema
121  * Under construction
122  *
123  * Revision 1.1  2002/06/25 13:15:39  bronsema
124  * Initial creation
125  *****************************************************************************/
126
127 define("LOAD_MAPSESSION", 1);
128
129 include("../session.inc.php");
130
131 // give lots of time to draw the map
132 set_time_limit( 300 );
133
134 $nWidth   = isset( $http_form_vars["MapWidth"] )     
135                                             ? $http_form_vars["MapWidth"] : 400;
136 $nHeight  = isset( $http_form_vars["MapHeight"] )   
137                                            ? $http_form_vars["MapHeight"] : 400;
138 $bShowPreview = isset( $http_form_vars["bShowPreview"] )
139                                           ? $http_form_vars["bShowPreview"] : 0;
140 $bShowDownload = isset( $http_form_vars["bShowDownload"] )
141                                          ? $http_form_vars["bShowDownload"] : 0;
142                                         
143 //figure out the font file path
144 $szFontFile = $oMapSession->oMap->fontsetfilename;
145 if (substr($szFontFile, 0, 1) != "/" && substr($szFontFile, 1, 1) != ":")
146 {
147     if (substr($_SESSION['gszMapPath'], -1) != "/" &&
148         substr($_SESSION['gszMapPath'], -1) != "\\")
149     {
150         $sep = "/";
151     }
152     else
153     {
154         $sep = "";
155     }
156     $szFontFile = realpath( $_SESSION['gszMapPath'].$sep.$szFontFile );
157 }
158 else
159 {
160     $szFontFile = realpath( $szFontFile );
161 }
162 $szFontDir = dirname( $szFontFile );
163 $aFontList = file( $szFontFile );
164 $aFonts = array();
165 foreach($aFontList as $szFontEntry)
166 {
167     $nSep = strpos($szFontEntry, " ");
168     $szFont = trim(substr($szFontEntry, 0, $nSep ));
169     $szFontTTF = trim(substr($szFontEntry, $nSep ));
170     $aFonts[$szFont] = $szFontTTF;
171 }                                         
172
173 /* ============================================================================
174  * check if the session production text file exists else create one
175  * ========================================================================= */
176 checkSettingsFile( $_SESSION['gszTmpPath'].$http_form_vars['sid'].".txt",
177                     $nWidth, $nHeight );
178
179 /* ============================================================================
180  * Process settings etc.
181  * ========================================================================= */
182 if ( $bShowPreview == 1 || $bShowDownload == 1 )
183 {
184     // update the settings file
185     updateSettingsFile( $_SESSION['gszTmpPath'].$http_form_vars['sid'].".txt",
186                                                             $http_form_vars );
187 }
188 // include the settings file
189 include( $_SESSION['gszTmpPath'].$http_form_vars['sid'].".txt" );
190
191
192 $txtWidthPix = isset( $http_form_vars["MapWidth"] )
193                             ? $http_form_vars["MapWidth"] : $txtWidthPix;
194 $txtHeightPix= isset( $http_form_vars["MapHeight"] )
195                             ? $http_form_vars["MapHeight"] : $txtHeightPix;
196                             
197
198 /**
199  * Postcondition: This function checks to see if the settings file exists and
200  * will create a new one if it doesn't.
201  *
202  * @param $szFile string - The path and filename of the textfile to check.
203  * @param $nWidth integer - The default value of the width setting.
204  * @param $nHeight integer - The default value of the height setting.
205  * @return boolean - True if successful, false if not.
206  **/
207 function checkSettingsFile( $szFile, $nWidth, $nHeight )
208 {
209     // check to see if the file exists
210     if ( file_exists( $szFile ) )
211         return true;
212
213     // file does not exist so create it and default
214     $fp = fopen($szFile, 'w');
215
216     // set default values
217     $szBuffer = "<?php\n";
218     $szBuffer .= "\$chkTitleElem = 1;\n";
219     $szBuffer .= "\$txtTitleDesc = \"NCCOOS Coastal Observations\";\n";
220     $szBuffer .= "\$chkNeatElem = 1;\n";
221     $szBuffer .= "\$chkScalebarElem = 1;\n";
222     $szBuffer .= "\$chkLegendElem = 0;\n";
223     $szBuffer .= "\$selScalebarPos = \"BL\";\n";
224     $szBuffer .= "\$selLegendPos = \"TR\";\n";
225     $szBuffer .= "\$selFontSize = \"12\";\n";
226     $szBuffer .= "\$txtWidthPix = \"$nWidth\";\n";
227     $szBuffer .= "\$txtHeightPix = \"$nHeight\";\n";
228     $szBuffer .= "\$selImageFormat = \"JPEG\";\n";
229     $szBuffer .= "\$selTitleFont = \"fritqat\";\n";
230     $szBuffer .= "\$selTitleFontFile = \"\";\n";
231     $szBuffer .= "\$selLegendFont = \"fritqat\";\n";
232     $szBuffer .= "\$selLegendFontFile = \"\";\n";
233     
234     $szBuffer .= "?>";
235
236     // write the default settings
237     fwrite($fp, $szBuffer);
238
239     // close the file
240     fclose($fp);
241     echo $szBuffer;
242     
243     // return
244     return true;
245
246 // end checkSettingsFile() function
247 }
248
249 /**
250  * Postcondition - This method will open the given setting file and update the
251  * necessary values according to the array of URL values passed to it.
252  *
253  * @param $szFile string - The path and filename of the settings file to update.
254  * @param $url mixed array - An array of values as passed through the url used
255  *                           to update the settings file.
256  * @return boolean - True if successful, false if not.
257  **/
258 function updateSettingsFile( $szFile, $url )
259 {
260     // check to see if the file exists
261     if ( file_exists( $szFile ) )
262         unlink( $szFile );
263
264     // re-create the file
265     $fp = fopen($szFile, 'w');
266
267     // process checkbox values
268     if ( !isset( $url["chkTitleElem"] ) ) $url["chkTitleElem"] = 0;
269     if ( !isset( $url["chkNeatElem"] ) ) $url["chkNeatElem"] = 0;
270     if ( !isset( $url["chkScalebarElem"] ) ) $url["chkScalebarElem"] = 0;
271     if ( !isset( $url["chkLegendElem"] ) ) $url["chkLegendElem"] = 0;
272
273     // set default values
274     $szBuffer = "<?php\n";
275     $szBuffer .= "\$chkTitleElem = ".$url["chkTitleElem"].";\n";
276     $szBuffer .= "\$txtTitleDesc = \"".$url["txtTitleDesc"]."\";\n";
277     $szBuffer .= "\$chkNeatElem = ".$url["chkNeatElem"].";\n";
278     $szBuffer .= "\$chkScalebarElem = ".$url["chkScalebarElem"].";\n";
279     $szBuffer .= "\$chkLegendElem = ".$url["chkLegendElem"].";\n";
280     $szBuffer .= "\$selScalebarPos = \"".$url["selScalebarPos"]."\";\n";
281     $szBuffer .= "\$selLegendPos = \"".$url["selLegendPos"]."\";\n";
282     $szBuffer .= "\$selFontSize = \"".$url["selFontSize"]."\";\n";
283     $szBuffer .= "\$txtWidthPix = \"".$url["txtWidthPix"]."\";\n";
284     $szBuffer .= "\$txtHeightPix = \"".$url["txtHeightPix"]."\";\n";
285     $szBuffer .= "\$selImageFormat = \"".$url["selImageFormat"]."\";\n";
286     $szBuffer .= "\$szFontDir = \"".$GLOBALS["szFontDir"]."\";\n";
287     $szBuffer .= "\$selTitleFont = \"".$url["titleFont"]."\";\n";
288     $szBuffer .= "\$selTitleFontFile = \"".$GLOBALS["aFonts"][$url["titleFont"]]."\";\n";
289     $szBuffer .= "\$selLegendFont = \"".$url["legendFont"]."\";\n";
290     $szBuffer .= "\$selLegendFontFile = \"".$GLOBALS["aFonts"][$url["legendFont"]]."\";\n";
291     $szBuffer .= "?>";
292
293     // write the default settings
294     fwrite($fp, $szBuffer);
295
296     // close the file
297     fclose($fp);
298     
299   
300     // return
301     return true;
302
303 // end updateSettingsFile() function
304 }
305
306 /**
307  * This function restores the characters that give problems when passed through
308  * a URL.
309  *
310  * @param $szString string - The string to fix.
311  * @param $bHTML boolean - Optional flag to indicate if HTML quote is needed.
312  * @return string - The restored string.
313  **/
314 function restoreChars( $szString, $bHTML = false )
315 {
316     // check for #!# and replace with \
317     $szString = str_replace( "#!#", "\\", $szString );
318
319     // check for #!!# and replace with '
320     $szString = str_replace( "#!!#", "'", $szString );
321
322     // check for #!!!# and replace with "
323     if ( $bHTML )
324         $szString = str_replace( "#!!!#", "&quot;", $szString );
325     else
326         $szString = str_replace( "#!!!#", "\"", $szString );
327
328     // return string
329     return $szString;
330
331 // end restorChars() function
332 }
333 ?>
334
Note: See TracBrowser for help on using the browser.