/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/fboprime/rscsx.inc
ViewVC logotype

Annotation of /to_be_filed/webprojs/php_libraries/php_library/fboprime/rscsx.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 9 months ago) by dashley
File size: 59787 byte(s)
Initial commit.
1 dashley 35 <?php
2     //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/rscsx.inc,v 1.16 2006/11/05 01:07:30 dashley Exp $
3     //--------------------------------------------------------------------------------------------------------------
4     //rscsx.inc--FboPrime Database rscs Table Manipulation Functions Not Required by Day View Scheduler
5     //Copyright (C) 2006 David T. Ashley
6     //
7     //This program is free software; you can redistribute it and/or
8     //modify it under the terms of the GNU General Public License
9     //as published by the Free Software Foundation; either version 2
10     //of the License, or (at your option) any later version.
11     //
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.
16     //
17     //You should have received a copy of the GNU General Public License
18     //along with this program; if not, write to the Free Software
19     //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20     //********************************************************************************
21     //
22     require_once("cslx.inc");
23     require_once("datefunc.inc");
24     require_once("db.inc");
25     require_once("global.inc");
26     require_once("rscs.inc");
27     require_once("sguid.inc");
28     //
29     //--------------------------------------------------------------------------------------------------------------
30     //The set of characters allowed in the initials field.
31     //
32     define("RSCS_INITIALS_ALLOWEDCHARS", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:-_.,;'0123456789");
33     define("RSCS_SHORTDESC_ALLOWEDCHARS", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:-_.,;'0123456789");
34     define("RSCS_LONGDESC_ALLOWEDCHARS", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:-_.,;'0123456789");
35     //
36     //--------------------------------------------------------------------------------------------------------------
37     //Modifies a RSCS record. The record is keyed by the index of the record in.
38     //All errors are tolerated except three:
39     // a)Record does not exist, so can't modify it. No changes made.
40     // b)Editing collision: SGUID shows concurrent editing. In this case, no changes are made.
41     // c)Unknown query failure. Presumably no changes made.
42     //
43     //All error flags are FALSE if no error, TRUE if error.
44     //
45     //If all are FALSE, operation probably succeeded.
46     //
47     function RSCS_modify_record(
48     $record_in,
49     &$record_noexist_error_out,
50     &$editing_collision_error_out,
51     &$query_failure_error_out
52     )
53     {
54     global $GLOBAL_dbhandle;
55     global $GLOBAL_dblocked;
56    
57     //Assume by default no errors.
58     $record_noexist_error_out = FALSE;
59     $editing_collision_error_out = FALSE;
60     $query_failure_error_out = FALSE;
61    
62     //Grab a new SGUID. This will be used for the mod stamp in the event we can commit
63     //the changes.
64     $new_sguid = SGUID_sguid();
65    
66     //Lock the database using the recursive critical section method (discussed in the
67     //manual). This is necessary because the test for presence and the modification have to
68     //be combined atomically.
69     //
70     $db_was_locked = $GLOBAL_dblocked;
71     if (! $GLOBAL_dblocked)
72     {
73     DB_db_lock();
74     $GLOBAL_dblocked = TRUE;
75     }
76     //
77     //Try to yank the record with the specified idx.
78     $existing_record = RSCS_retrieve_by_idx($record_in["idx"]);
79    
80     //If the record doesn't already exist, we can't go forward. Error out.
81     if ($existing_record === FALSE)
82     {
83     //Unlock the database (if it was locked) using the recursive critical section
84     //method.
85     if (! $db_was_locked)
86     {
87     DB_db_unlock();
88     $GLOBAL_dblocked = FALSE;
89     }
90    
91     $record_noexist_error_out = TRUE;
92    
93     return; //Back to caller.
94     }
95    
96     //Test for an editing collision.
97     if ($existing_record["crmodsguid"] != $record_in["crmodsguid"])
98     {
99     //Unlock the database (if it was locked) using the recursive critical section
100     //method.
101     if (! $db_was_locked)
102     {
103     DB_db_unlock();
104     $GLOBAL_dblocked = FALSE;
105     }
106    
107     $editing_collision_error_out = TRUE;
108    
109     return; //Back to caller.
110     }
111    
112     //Build the query string with each successive parameter.
113     //
114     //type
115     //------
116     if (! isset($record_in["type"]))
117     $pushval = RSCS_TYPE_AIRCRAFT;
118     else
119     $pushval = $record_in["type"];
120     $query_string = "UPDATE rscs SET type=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"";
121     //
122     //status
123     //------
124     if (! isset($record_in["status"]))
125     $pushval = RSCS_STATUS_ONLINE;
126     else
127     $pushval = $record_in["status"];
128     $query_string .= (", status=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
129     //
130     //disporder
131     //---------
132     if (! isset($record_in["disporder"]))
133     $pushval = 0;
134     else
135     $pushval = $record_in["disporder"];
136     $query_string .= (", disporder=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
137     //
138     //longdesc
139     //--------
140     if (! isset($record_in["longdesc"]))
141     $pushval = "";
142     else
143     $pushval = $record_in["longdesc"];
144     $query_string .= (", longdesc=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
145     //
146     //shortdesc
147     //---------
148     if (! isset($record_in["shortdesc"]))
149     $pushval = "";
150     else
151     $pushval = $record_in["shortdesc"];
152     $query_string .= (", shortdesc=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
153     //
154     //initials
155     //--------
156     if (! isset($record_in["initials"]))
157     $pushval = "";
158     else
159     $pushval = $record_in["initials"];
160     $query_string .= (", initials=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
161     //
162     //rstdtime
163     //--------
164     if (! isset($record_in["rstdtime"]))
165     $pushval = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
166     else
167     $pushval = $record_in["rstdtime"];
168     $query_string .= (", rstdtime=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
169     //
170     //schedaheadhrs
171     //-------------
172     if (! isset($record_in["schedaheadhrs"]))
173     $pushval = (int) 0;
174     else
175     $pushval = $record_in["schedaheadhrs"];
176     $query_string .= (", schedaheadhrs=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
177     //
178     //usercorres
179     //----------
180     if (! isset($record_in["usercorres"]))
181     $pushval = (int) 0;
182     else
183     $pushval = $record_in["usercorres"];
184     $query_string .= (", usercorres=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
185     //
186     //crmodsguid
187     //----------
188     $pushval = $new_sguid;
189     $query_string .= (", crmodsguid=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
190     //
191     //echo " " . $query_string . " ";
192     //
193     //idx qualifier
194     //-------------
195     $pushval = $record_in["idx"];
196     $query_string .= (" WHERE idx=\"" . mysql_real_escape_string ($pushval, $GLOBAL_dbhandle) . "\"");
197    
198     //echo "<br>";
199     //print_r($query_string);
200     //echo "<br>";
201    
202     //Execute the query to insert the record.
203     $result = mysql_query($query_string, $GLOBAL_dbhandle);
204     //
205     //If the update failed, set the query failure flag.
206     if ($result == FALSE)
207     {
208     $query_failure_error_out = TRUE;
209     }
210    
211     //Unlock the database (if it was locked) using the recursive critical section
212     //method.
213     if (! $db_was_locked)
214     {
215     DB_db_unlock();
216     $GLOBAL_dblocked = FALSE;
217     }
218     }
219     //
220     //--------------------------------------------------------------------------------------------------------------
221     //Retrieves an associative array containing full information about the resource whose index is
222     //passed, or FALSE if it can't be located.
223     //
224     function RSCS_retrieve_by_idx($idx)
225     {
226     global $GLOBAL_dbhandle;
227    
228     //Form the query string.
229     $query_string = "SELECT * FROM rscs WHERE idx=\""
230     .
231     mysql_real_escape_string($idx, $GLOBAL_dbhandle)
232     .
233     "\"";
234    
235     //Execute the query.
236     $result = mysql_query($query_string, $GLOBAL_dbhandle);
237    
238     if ($result === FALSE)
239     {
240     //Unknown query failure. Return FALSE to the caller. No need to free,
241     //as this is not a result.
242     $rv = FALSE;
243     }
244     else
245     {
246     //Figure out how many rows in the result.
247     $nrows = mysql_num_rows($result);
248    
249     if ($nrows == 0)
250     {
251     //No rows in the result. The query failed to give us a record, but still
252     //we need to free the result set.
253    
254     //Free the result.
255     mysql_free_result($result);
256    
257     //The caller gets FALSE. No record with that SID.
258     $rv = FALSE;
259     }
260     else
261     {
262     //We have at least one record. Assume just one, because the IDX is supposed
263     //to be unique.
264     $rv = mysql_fetch_assoc($result); //Get the associative record.
265    
266     //Free the result.
267     mysql_free_result($result);
268     }
269    
270     //Return the value to the caller.
271     return($rv);
272     }
273     }
274     //
275     //--------------------------------------------------------------------------------------------------------------
276     //Retrieves an array containing the indices of all flight instructors in the resources
277     //table that are online, or FALSE if none exist.
278     //
279     function RSCS_get_fi_online_idxs()
280     {
281     global $GLOBAL_dbhandle;
282    
283     //Form the query string.
284     $query_string = "SELECT idx FROM rscs WHERE type=\""
285     .
286     mysql_real_escape_string((string)RSCS_TYPE_FLIGHTINSTRUCTOR, $GLOBAL_dbhandle)
287     .
288     "\" AND status=\""
289     .
290     mysql_real_escape_string((string)RSCS_STATUS_ONLINE, $GLOBAL_dbhandle)
291     .
292     "\"";
293    
294     //Execute the query.
295     $result = mysql_query($query_string, $GLOBAL_dbhandle);
296    
297     if ($result === FALSE)
298     {
299     //Unknown query failure. Return FALSE to the caller. No need to free,
300     //as this is not a result.
301     $rv = FALSE;
302     }
303     else
304     {
305     //Figure out how many rows in the result.
306     $nrows = mysql_num_rows($result);
307    
308     if ($nrows == 0)
309     {
310     //No rows in the result. The query failed to give us a record, but still
311     //we need to free the result set.
312    
313     //Free the result.
314     mysql_free_result($result);
315    
316     //The caller gets FALSE. No records.
317     $rv = FALSE;
318     }
319     else
320     {
321     //We have at least one record. Grab the indices.
322     //
323     for ($i=0; $i<$nrows; $i++)
324     {
325     $temp = mysql_fetch_assoc($result);
326     $rv[$i] = $temp["idx"];
327     }
328    
329     //Free the result.
330     mysql_free_result($result);
331     }
332    
333     //Return the value to the caller.
334     return($rv);
335     }
336     }
337     //
338     //--------------------------------------------------------------------------------------------------------------
339     //Retrieves an array containing the indices of all aircraft/simulators in the resources
340     //table that are online, or FALSE if none exist.
341     //
342     function RSCS_get_acftsim_online_idxs()
343     {
344     global $GLOBAL_dbhandle;
345    
346     //Form the query string.
347     $query_string = "SELECT idx FROM rscs WHERE ( type=\""
348     .
349     mysql_real_escape_string((string)RSCS_TYPE_AIRCRAFT, $GLOBAL_dbhandle)
350     .
351     "\" OR type=\""
352     .
353     mysql_real_escape_string((string)RSCS_TYPE_SIMULATOR, $GLOBAL_dbhandle)
354     .
355     "\" ) AND status=\""
356     .
357     mysql_real_escape_string((string)RSCS_STATUS_ONLINE, $GLOBAL_dbhandle)
358     .
359     "\"";
360    
361     //Execute the query.
362     $result = mysql_query($query_string, $GLOBAL_dbhandle);
363    
364     if ($result === FALSE)
365     {
366     //Unknown query failure. Return FALSE to the caller. No need to free,
367     //as this is not a result.
368     $rv = FALSE;
369     }
370     else
371     {
372     //Figure out how many rows in the result.
373     $nrows = mysql_num_rows($result);
374    
375     if ($nrows == 0)
376     {
377     //No rows in the result. The query failed to give us a record, but still
378     //we need to free the result set.
379    
380     //Free the result.
381     mysql_free_result($result);
382    
383     //The caller gets FALSE. No records.
384     $rv = FALSE;
385     }
386     else
387     {
388     //We have at least one record. Grab the indices.
389     //
390     for ($i=0; $i<$nrows; $i++)
391     {
392     $temp = mysql_fetch_assoc($result);
393     $rv[$i] = $temp["idx"];
394     }
395    
396     //Free the result.
397     mysql_free_result($result);
398     }
399    
400     //Return the value to the caller.
401     return($rv);
402     }
403     }
404     //
405     //--------------------------------------------------------------------------------------------------------------
406     //Retrieves an array containing the indices of _all_ resources, ordered by status, sort index, then index
407     //for display on the resource list page.
408     //
409     function RSCS_get_idxs_all_rscslist_a()
410     {
411     global $GLOBAL_dbhandle;
412    
413     //Form the query string.
414     $query_string = "SELECT idx FROM rscs ORDER BY status DESC, disporder ASC, idx ASC";
415    
416     //Execute the query.
417     $result = mysql_query($query_string, $GLOBAL_dbhandle);
418    
419     if ($result === FALSE)
420     {
421     //Unknown query failure. Return FALSE to the caller. No need to free,
422     //as this is not a result.
423     $rv = FALSE;
424     }
425     else
426     {
427     //Figure out how many rows in the result.
428     $nrows = mysql_num_rows($result);
429    
430     if ($nrows == 0)
431     {
432     //No rows in the result. The query failed to give us a record, but still
433     //we need to free the result set.
434    
435     //Free the result.
436     mysql_free_result($result);
437    
438     //The caller gets FALSE. No records.
439     $rv = FALSE;
440     }
441     else
442     {
443     //We have at least one record. Grab the indices.
444     //
445     for ($i=0; $i<$nrows; $i++)
446     {
447     $temp = mysql_fetch_assoc($result);
448     $rv[$i] = $temp["idx"];
449     }
450    
451     //Free the result.
452     mysql_free_result($result);
453     }
454    
455     //Return the value to the caller.
456     return($rv);
457     }
458     }
459     //
460     //--------------------------------------------------------------------------------------------------------------
461     //Retrieves an array containing the short description, medium description, database index, status, and
462     //corresponding user for each entry in the resources table. The array returned is indexed by the database index
463     //(not sequentially), meaning that some gaps in the indexing may occur.
464     //
465     //Returns FALSE if no records.
466     //
467     function RSCS_get_key_info_rscslist_a()
468     {
469     global $GLOBAL_dbhandle;
470    
471     //Form the query string.
472     $query_string = "SELECT idx,type,status,initials,shortdesc,usercorres FROM rscs";
473    
474     //Execute the query.
475     $result = mysql_query($query_string, $GLOBAL_dbhandle);
476    
477     if ($result === FALSE)
478     {
479     //Unknown query failure. Return FALSE to the caller. No need to free,
480     //as this is not a result.
481     $rv = FALSE;
482     }
483     else
484     {
485     //Figure out how many rows in the result.
486     $nrows = mysql_num_rows($result);
487    
488     if ($nrows == 0)
489     {
490     //No rows in the result. The query failed to give us a record, but still
491     //we need to free the result set.
492    
493     //Free the result.
494     mysql_free_result($result);
495    
496     //The caller gets FALSE. No records.
497     $rv = FALSE;
498     }
499     else
500     {
501     //We have at least one record. Grab the data.
502     //
503     for ($i=0; $i<$nrows; $i++)
504     {
505     $temp = mysql_fetch_assoc($result);
506     $rv[$temp["idx"]] = $temp;
507     }
508    
509     //Free the result.
510     mysql_free_result($result);
511     }
512    
513     //Return the value to the caller.
514     return($rv);
515     }
516     }
517     //
518     //--------------------------------------------------------------------------------------------------------------
519     //Renumbers the disporder fields of the resource table at a fixed interval.
520     //
521     function RSCS_renumber_disporder_autointerval()
522     {
523     global $GLOBAL_dblocked;
524     global $GLOBAL_dbhandle;
525    
526     $renumber_interval = 100; //Interval to use. 100 should be large enough for any practical
527     //number of resources.
528    
529     //Lock the database using the recursive locking protocol to ensure that there won't be
530     //any changes while we are going through tampering with each resource.
531     //
532     $db_was_locked = $GLOBAL_dblocked;
533     if (! $GLOBAL_dblocked)
534     {
535     DB_db_lock();
536     $GLOBAL_dblocked = TRUE;
537     }
538     //-----------------------------------------------
539     //Get the complete set of indices from the resource table. We want to preserve the old
540     //order, so primary sort key is the display order, but then we have a couple (somewhat
541     //arbitrary) tiebreakers. We calculate the value FALSE (in place of an array)
542     //if something goes wrong.
543     //
544     //Form the query string.
545     $query_string = "SELECT idx FROM rscs ORDER BY disporder ASC, status DESC, idx ASC";
546    
547     //Execute the query.
548     $result = mysql_query($query_string, $GLOBAL_dbhandle);
549    
550     if ($result === FALSE)
551     {
552     //Unknown query failure. Return FALSE to the caller. No need to free,
553     //as this is not a result.
554     $indices = FALSE;
555     }
556     else
557     {
558     //Figure out how many rows in the result.
559     $nrows = mysql_num_rows($result);
560    
561     if ($nrows == 0)
562     {
563     //No rows in the result. The query failed to give us a record, but still
564     //we need to free the result set.
565    
566     //Free the result.
567     mysql_free_result($result);
568    
569     //The caller gets FALSE. No records.
570     $indices = FALSE;
571     }
572     else
573     {
574     //We have at least one record. Grab the indices.
575     //
576     for ($i=0; $i<$nrows; $i++)
577     {
578     $temp = mysql_fetch_assoc($result);
579     $indices[$i] = $temp["idx"];
580     }
581    
582     //Free the result.
583     mysql_free_result($result);
584     }
585     }
586    
587     //-----------------------------------------------
588     //If we had success in getting the list of indices (in the order we want),
589     //loop through them all and give them the right values. We loop backwards to avoid
590     //changing resource order in the event that the httpd process dies in the middle of this.
591     //We also need to change the modification sguid to make sure any editing collisions
592     //will be detected.
593     //
594     if ($indices !== FALSE)
595     {
596     $n = count($indices);
597     $number_to_assign = $n * $renumber_interval;
598    
599     for ($i=0; $i<$n; $i++)
600     {
601     $sguid = SGUID_sguid();
602    
603     $target = $indices[$n-1-$i];
604    
605     mysql_query("UPDATE rscs SET disporder=\""
606     .
607     (string)(($n - $i) * $renumber_interval)
608     .
609     "\", crmodsguid=\""
610     .
611     $sguid
612     .
613     "\" WHERE idx=\""
614     .
615     $target
616     .
617     "\"", $GLOBAL_dbhandle);
618     }
619     }
620    
621     //-----------------------------------------------
622     //Unlock the database using the recursive locking protocol.
623     //
624     if (! $db_was_locked)
625     {
626     DB_db_unlock();
627     $GLOBAL_dblocked = FALSE;
628     }
629     }
630     //
631     //--------------------------------------------------------------------------------------------------------------
632     //Maps from the resource status to a short description for the resource views.
633     //
634     function RSCS_status_map_long($status_in)
635     {
636     switch($status_in)
637     {
638     default:
639     {
640     $rv = "Unknown";
641    
642     break;
643     }
644     case RSCS_STATUS_OFFLINE :
645     {
646     $rv = "Offline";
647    
648     break;
649     }
650     case RSCS_STATUS_ONLINE :
651     {
652     $rv = "Online";
653    
654     break;
655     }
656     }
657    
658     return($rv);
659     }
660     //--------------------------------------------------------------------------------------------------------------
661     //Maps from the resource status to a short description for the resource views.
662     //
663     function RSCS_type_map_long($status_in)
664     {
665     switch($status_in)
666     {
667     default:
668     {
669     $rv = "Unknown";
670    
671     break;
672     }
673     case RSCS_TYPE_AIRCRAFT :
674     {
675     $rv = "Aircraft";
676    
677     break;
678     }
679     case RSCS_TYPE_SIMULATOR :
680     {
681     $rv = "Simulator";
682    
683     break;
684     }
685     case RSCS_TYPE_FLIGHTINSTRUCTOR :
686     {
687     $rv = "Flight Instructor";
688    
689     break;
690     }
691     }
692    
693     return($rv);
694     }
695     //--------------------------------------------------------------------------------------------------------------
696     //--------------------------------------------------------------------------------------------------------------
697     //Returns the HTML that should be used to identify the resource index on the EDIT and ADD pages. HTML may
698     //be marked up with <i> and <b> and includes the trailing colon.
699     //
700     function RSCS_idx_id_html_01()
701     {
702     return("<i>idx:</i>");
703     }
704     //--------------------------------------------------------------------------------------------------------------
705     //Returns the HTML that should be used to display the resource index on the EDIT and ADD pages.
706     //
707     function RSCS_idx_disp_html_01($idx_in)
708     {
709     $rv = number_format($idx_in);
710     return($rv);
711     }
712     //--------------------------------------------------------------------------------------------------------------
713     //Returns the HTML that should be used to identify the resource index description on the EDIT and ADD pages.
714     //HTML may be marked up with <i>, <b>, and <b>.
715     //
716     function RSCS_idx_desc_html_01()
717     {
718     $rv = "The <i>idx</i> field is assigned automatically by the database "
719     . "when a resource is created and may not be modified.";
720    
721     return($rv);
722     }
723     //--------------------------------------------------------------------------------------------------------------
724     //--------------------------------------------------------------------------------------------------------------
725     //Returns the HTML that should be used to identify the resource type on the EDIT and ADD pages. HTML may
726     //be marked up with <i> and <b> and includes the trailing colon.
727     //
728     function RSCS_type_id_html_01()
729     {
730     return("<i>type:</i>");
731     }
732     //--------------------------------------------------------------------------------------------------------------
733     //Returns the HTML that should be used to display the resource type select control on the EDIT and ADD pages.
734     //
735     function RSCS_type_disp_html_01($type_in)
736     {
737     //Turn the input into a numeric value. If it can't be turned into a numeric value,
738     //make it an aircraft.
739     if (is_numeric($type_in))
740     {
741     $type_in = (int)$type_in;
742     if (
743     ($type_in != RSCS_TYPE_AIRCRAFT)
744     &&
745     ($type_in != RSCS_TYPE_SIMULATOR)
746     &&
747     ($type_in != RSCS_TYPE_FLIGHTINSTRUCTOR)
748     )
749     {
750     //This is nothing we recognize. Assume aircraft.
751     $type_in = (int)RSCS_TYPE_AIRCRAFT;
752     }
753     }
754     else
755     {
756     //This is nothing we recognize. Assume aircraft.
757     $type_in = (int)RSCS_TYPE_AIRCRAFT;
758     }
759    
760     //Do the control.
761     $rv = "<select name=\"type\">";
762     //--------
763     $rv .= "<option value=\"" . (string)RSCS_TYPE_AIRCRAFT . "\"";
764     if ($type_in == RSCS_TYPE_AIRCRAFT)
765     $rv .= " SELECTED";
766     $rv .= ">Aircraft";
767     //--------
768     $rv .= "<option value=\"" . (string)RSCS_TYPE_SIMULATOR . "\"";
769     if ($type_in == RSCS_TYPE_SIMULATOR)
770     $rv .= " SELECTED";
771     $rv .= ">Simulator";
772     //--------
773     $rv .= "<option value=\"" . (string)RSCS_TYPE_FLIGHTINSTRUCTOR . "\"";
774     if ($type_in == RSCS_TYPE_FLIGHTINSTRUCTOR)
775     $rv .= " SELECTED";
776     $rv .= ">Flight Instructor";
777     //
778     $rv .= "</SELECT>";
779    
780     return($rv);
781     }
782     //--------------------------------------------------------------------------------------------------------------
783     //Returns the HTML that should be used to identify the resource index description on the EDIT and ADD pages.
784     //HTML may be marked up with <i>, <b>, and <b>.
785     //
786     function RSCS_type_desc_html_01()
787     {
788     $rv = "The <i>type</i> identifies whether the resource is an aircraft, a simulator, "
789     . "or a flight instructor.";
790    
791     return($rv);
792     }
793     //--------------------------------------------------------------------------------------------------------------
794     //--------------------------------------------------------------------------------------------------------------
795     //Returns the HTML that should be used to identify the resource status on the EDIT and ADD pages. HTML may
796     //be marked up with <i> and <b> and includes the trailing colon.
797     //
798     function RSCS_status_id_html_01()
799     {
800     return("<i>status:</i>");
801     }
802     //--------------------------------------------------------------------------------------------------------------
803     //Returns the HTML that should be used to display the resource status select control on the EDIT and ADD pages.
804     //
805     function RSCS_status_disp_html_01($status_in)
806     {
807     //Turn the input into a numeric value. If it can't be turned into a numeric value,
808     //make it online.
809     if (is_numeric($status_in))
810     {
811     $status_in = (int)$status_in;
812     if (
813     ($status_in != RSCS_STATUS_OFFLINE)
814     &&
815     ($status_in != RSCS_STATUS_ONLINE)
816     )
817     {
818     //This is nothing we recognize. Assume online.
819     $status_in = (int)RSCS_STATUS_ONLINE;
820     }
821     }
822     else
823     {
824     //This is nothing we recognize. Assume online.
825     $status_in = (int)RSCS_STATUS_ONLINE;
826     }
827    
828     //Do the control.
829     $rv = "<select name=\"status\">";
830     //--------
831     $rv .= "<option value=\"" . (string)RSCS_STATUS_OFFLINE . "\"";
832     if ($status_in == RSCS_STATUS_OFFLINE)
833     $rv .= " SELECTED";
834     $rv .= ">Offline";
835     //--------
836     $rv .= "<option value=\"" . (string)RSCS_STATUS_ONLINE . "\"";
837     if ($status_in == RSCS_STATUS_ONLINE)
838     $rv .= " SELECTED";
839     $rv .= ">Online";
840     //--------
841     $rv .= "</SELECT>";
842    
843     return($rv);
844     }
845     //--------------------------------------------------------------------------------------------------------------
846     //Returns the HTML that should be used to identify the resource index description on the EDIT and ADD pages.
847     //HTML may be marked up with <i>, <b>, and <b>.
848     //
849     function RSCS_status_desc_html_01()
850     {
851     $rv = "The <i>status</i> identifies whether a resource is in service.&nbsp; A resource that is <i>offline</i> "
852     . "is not displayed in scheduling views and cannot be scheduled.&nbsp; Placing a resource <i>offline</i> "
853     . "will make the resource invisible without deleting information about the resource.";
854    
855     return($rv);
856     }
857     //--------------------------------------------------------------------------------------------------------------
858     //--------------------------------------------------------------------------------------------------------------
859     //Returns the HTML that should be used to identify the disporderstatus on the EDIT and ADD pages. HTML may
860     //be marked up with <i> and <b> and includes the trailing colon.
861     //
862     function RSCS_disporder_id_html_01()
863     {
864     return("<i>disporder:</i>");
865     }
866     //--------------------------------------------------------------------------------------------------------------
867     //Returns the HTML that should be used to display the disporder form field on the EDIT and ADD pages.
868     //
869     function RSCS_disporder_disp_html_01($disporder_in)
870     {
871     //Turn the input into a numeric value. If it can't be turned into a numeric value,
872     //make it online.
873     if (is_numeric($disporder_in))
874     {
875     $disporder_in = (int)$disporder_in;
876     if ($disporder_in <= 0)
877     {
878     //Can't be non-positive integer.
879     $disporder_in = 1;
880     }
881     }
882     else
883     {
884     //This is nothing we recognize. Assume number 1.
885     $disporder_in = 1;
886     }
887    
888     //Do the text input field.
889     $rv = "<input type=\"text\" name=\"disporder\" size=\"15\" value=\""
890     .
891     (string)$disporder_in
892     .
893     "\">";
894    
895     return($rv);
896     }
897     //--------------------------------------------------------------------------------------------------------------
898     //Returns the HTML that should be used to identify the resource index description on the EDIT and ADD pages.
899     //HTML may be marked up with <i>, <b>, and <b>.
900     //
901     function RSCS_disporder_desc_html_01()
902     {
903     $rv = "The <i>disporder</i> is a positive integer that defines which resource is displayed first "
904     . "in contexts where information about more than one resource may be displayed.&nbsp; Resources "
905     . "with the smaller <i>disporder</i> field are displayed first.&nbsp; An option to renumber the "
906     . "<i>disporder</i> fields exists on the resource list page.";
907    
908     return($rv);
909     }
910     //--------------------------------------------------------------------------------------------------------------
911     //--------------------------------------------------------------------------------------------------------------
912     //Returns the HTML that should be used to identify the initials on the EDIT and ADD pages. HTML may
913     //be marked up with <i> and <b> and includes the trailing colon.
914     //
915     function RSCS_initials_id_html_01()
916     {
917     return("<i>initials:</i>");
918     }
919     //--------------------------------------------------------------------------------------------------------------
920     //Returns the HTML that should be used to display the initials form field on the EDIT and ADD pages.
921     //
922     function RSCS_initials_disp_html_01($initials_in)
923     {
924     //Do the text input field.
925     $rv = "<input type=\"text\" name=\"initials\" size=\"15\" value=\""
926     .
927     htmlentities((string)$initials_in)
928     .
929     "\">";
930    
931     return($rv);
932     }
933     //--------------------------------------------------------------------------------------------------------------
934     //Returns the HTML that should be used to identify the resource index description on the EDIT and ADD pages.
935     //HTML may be marked up with <i>, <b>, and <b>.
936     //
937     function RSCS_initials_desc_html_01()
938     {
939     $rv = "The <i>initials</i> field is the shortest possible description to uniquely identify an "
940     . "aircraft, simulator, or flight instructor.&nbsp; For an aircraft, this field traditionally "
941     . "is the registration number of the aircraft (i.e. &quot;N1234N&quot;).&nbsp; For a flight instructor, "
942     . "this field traditionally holds just the instructor's initials (i.e. &quot;J.S.&quot;).";
943    
944     return($rv);
945     }
946     //--------------------------------------------------------------------------------------------------------------
947     //--------------------------------------------------------------------------------------------------------------
948     //Returns the HTML that should be used to identify the shortdesc on the EDIT and ADD pages. HTML may
949     //be marked up with <i> and <b> and includes the trailing colon.
950     //
951     function RSCS_shortdesc_id_html_01()
952     {
953     return("<i>shortdesc:</i>");
954     }
955     //--------------------------------------------------------------------------------------------------------------
956     //Returns the HTML that should be used to display the shortdesc form field on the EDIT and ADD pages.
957     //
958     function RSCS_shortdesc_disp_html_01($shortdesc_in)
959     {
960     //Do the text input field.
961     $rv = "<input type=\"text\" name=\"shortdesc\" size=\"50\" value=\""
962     .
963     htmlentities((string)$shortdesc_in)
964     .
965     "\">";
966    
967     return($rv);
968     }
969     //--------------------------------------------------------------------------------------------------------------
970     //Returns the HTML that should be used to identify the resource shortdesc description on the EDIT and ADD pages.
971     //HTML may be marked up with <i>, <b>, and <b>.
972     //
973     function RSCS_shortdesc_desc_html_01()
974     {
975     $rv = "The <i>shortdesc</i> field is the medium-length description to uniquely identify an "
976     . "aircraft, simulator, or flight instructor.&nbsp; For an aircraft, this field traditionally "
977     . "is the registration number of the aircraft (i.e. &quot;N1234N&quot;).&nbsp; For a flight instructor, "
978     . "this field traditionally holds the instructor's first initial and last name (i.e. &quot;J. Smith&quot;).";
979    
980     return($rv);
981     }
982     //--------------------------------------------------------------------------------------------------------------
983     //--------------------------------------------------------------------------------------------------------------
984     //Returns the HTML that should be used to identify the longdesc on the EDIT and ADD pages. HTML may
985     //be marked up with <i> and <b> and includes the trailing colon.
986     //
987     function RSCS_longdesc_id_html_01()
988     {
989     return("<i>longdesc:</i>");
990     }
991     //--------------------------------------------------------------------------------------------------------------
992     //Returns the HTML that should be used to display the longdesc form field on the EDIT and ADD pages.
993     //
994     function RSCS_longdesc_disp_html_01($longdesc_in)
995     {
996     //Do the text input field.
997     $rv = "<input type=\"text\" name=\"longdesc\" size=\"100\" value=\""
998     .
999     htmlentities((string)$longdesc_in)
1000     .
1001     "\">";
1002    
1003     return($rv);
1004     }
1005     //--------------------------------------------------------------------------------------------------------------
1006     //Returns the HTML that should be used to identify the resource longdesc description on the EDIT and ADD pages.
1007     //HTML may be marked up with <i>, <b>, and <b>.
1008     //
1009     function RSCS_longdesc_desc_html_01()
1010     {
1011     $rv = "The <i>longdesc</i> field is the longest description to uniquely identify an "
1012     . "aircraft, simulator, or flight instructor.&nbsp; For an aircraft, this field traditionally "
1013     . "is the registration number of the aircraft followed by the manufacturer and model "
1014     . "(i.e. &quot;N1234N Cessna 172P&quot;).&nbsp; For a flight instructor, "
1015     . "this field traditionally holds the instructor's last name, a comma, and then the first "
1016     . "name (i.e. &quot;Smith, John&quot;).";
1017    
1018     return($rv);
1019     }
1020     //--------------------------------------------------------------------------------------------------------------
1021     //--------------------------------------------------------------------------------------------------------------
1022     //Returns the HTML that should be used to identify the schedaheadhrs on the EDIT and ADD pages. HTML may
1023     //be marked up with <i> and <b> and includes the trailing colon.
1024     //
1025     function RSCS_schedaheadhrs_id_html_01()
1026     {
1027     return("<i>schedaheadhrs:</i>");
1028     }
1029     //--------------------------------------------------------------------------------------------------------------
1030     //Returns the HTML that should be used to display the schedaheadhrs form field on the EDIT and ADD pages.
1031     //
1032     function RSCS_schedaheadhrs_disp_html_01($schedaheadhrs_in)
1033     {
1034     //Turn the input into a numeric value. If it can't be turned into a numeric value,
1035     //make it online.
1036     if (is_numeric($schedaheadhrs_in))
1037     {
1038     $schedaheadhrs_in = (int)$schedaheadhrs_in;
1039     if ($schedaheadhrs_in < 0)
1040     {
1041     //Can't be negative integer.
1042     $schedaheadhrs_in = 0;
1043     }
1044     }
1045     else
1046     {
1047     //This is nothing we recognize. Assume number 0.
1048     $schedaheadhrs_in = 0;
1049     }
1050    
1051     //Do the text input field.
1052     $rv = "<input type=\"text\" name=\"schedaheadhrs\" size=\"15\" value=\""
1053     .
1054     (string)$schedaheadhrs_in
1055     .
1056     "\">";
1057    
1058     return($rv);
1059     }
1060     //--------------------------------------------------------------------------------------------------------------
1061     //Returns the HTML that should be used to identify the schedaheadhrs description on the EDIT and ADD pages.
1062     //HTML may be marked up with <i>, <b>, and <b>.
1063     //
1064     function RSCS_schedaheadhrs_desc_html_01()
1065     {
1066     $rv = "The <i>schedaheadhrs</i> is a non-negative integer that specifies the minimum number of hours that a "
1067     . "reservation must be made ahead of its start time by those without permission to violate scheduling rules.&nbsp; A "
1068     . "typical value for this field is 8.&nbsp; The intent "
1069     . "of the scheduling rules facilitated by this field is to ensure that an FBO has enough time to prepare an aircraft "
1070     . "and/or that a flight instructor has enough time to plan ahead for a lesson.&nbsp; A reservation that must be made "
1071     . "too close to the start time is typically made by calling the FBO.";
1072    
1073     return($rv);
1074     }
1075     //--------------------------------------------------------------------------------------------------------------
1076     //--------------------------------------------------------------------------------------------------------------
1077     //Returns the HTML that should be used to identify the usercorres on the EDIT and ADD pages. HTML may
1078     //be marked up with <i> and <b> and includes the trailing colon.
1079     //
1080     function RSCS_usercorres_id_html_01()
1081     {
1082     return("<i>usercorres:</i>");
1083     }
1084     //--------------------------------------------------------------------------------------------------------------
1085     //Returns the HTML that should be used to display the usercorres form field on the EDIT and ADD pages.
1086     //
1087     function RSCS_usercorres_disp_html_01($usercorres_in)
1088     {
1089     //Turn the input into a numeric value. If it can't be turned into a numeric value,
1090     //make it 0.
1091     if (is_numeric($usercorres_in))
1092     {
1093     $usercorres_in = (int)$usercorres_in;
1094     if ($usercorres_in < 0)
1095     {
1096     //Can't be negative integer.
1097     $usercorres_in = 0;
1098     }
1099     }
1100     else
1101     {
1102     //This is nothing we recognize. Assume number 0.
1103     $usercorres_in = 0;
1104     }
1105    
1106     //If the integer is non-zero, try to look up the user with that index.
1107     if ($usercorres_in != 0)
1108     {
1109     $userdata = USRS_retrieve_by_idx($usercorres_in);
1110     if ($userdata !== FALSE)
1111     {
1112     $userid = $userdata["userid"];
1113     }
1114     else
1115     {
1116     $userid = $usercorres_in;
1117     }
1118     }
1119     else
1120     {
1121     $userid = 0;
1122     }
1123    
1124     //Do the text input field.
1125     $rv = "<input type=\"text\" name=\"usercorres\" size=\"20\" value=\""
1126     .
1127     (string)$userid
1128     .
1129     "\">";
1130    
1131     return($rv);
1132     }
1133     //--------------------------------------------------------------------------------------------------------------
1134     //Returns the HTML that should be used to identify the schedaheadhrs description on the EDIT and ADD pages.
1135     //HTML may be marked up with <i>, <b>, and <b>.
1136     //
1137     function RSCS_usercorres_desc_html_01()
1138     {
1139     $rv = "The <i>usercorres</i> field specifies the user account of the flight instructor corresponding to the "
1140     . "resource, if the resource is a flight instructor.&nbsp; (It is not required that a flight instructor "
1141     . "resource be linked to a user account, but such linkage is the usual case.)&nbsp; If provided, this link "
1142     . "allows the scheduling software to send the flight instructor notification e-mails when a relevant scheduling "
1143     . "change is made, and to make other intelligent decisions about scheduling, permissions, and notification.&nbsp; "
1144     . "The user account must be specified as the userid of the account (i.e. &quot;jsmith&quot;).&nbsp; If "
1145     . "no user account should be linked to the resource, the integer "
1146     . "&quot;0&quot; should be used.";
1147    
1148     return($rv);
1149     }
1150     //--------------------------------------------------------------------------------------------------------------
1151     //--------------------------------------------------------------------------------------------------------------
1152     //Returns the HTML that should be used to identify the rstdtime on the EDIT and ADD pages. HTML may
1153     //be marked up with <i> and <b> and includes the trailing colon.
1154     //
1155     function RSCS_rstdtime_id_html_01()
1156     {
1157     return("<i>rstdtime:</i>");
1158     }
1159     //--------------------------------------------------------------------------------------------------------------
1160     //Returns the HTML that should be used to display the rstdtime form field on the EDIT and ADD pages.
1161     //
1162     function RSCS_rstdtime_disp_html_01($rstdtime_in)
1163     {
1164     $rv = "";
1165    
1166     $rstdtime_in = (string)$rstdtime_in; //Be sure it is a string.
1167    
1168     for ($i=0; $i<48; $i++) //For each half-hour time slot.
1169     {
1170     $hour_start = (int)($i >> 1);
1171     $minute_start = (int)(($i % 2) * 30);
1172    
1173     $hour_end = (int)((($i+1) % 48) >> 1);
1174     $minute_end = (int)(((($i+1) % 48) % 2) * 30);
1175    
1176     $time_string_start = DATEFUNC_stdtimenosec($hour_start, $minute_start);
1177     $time_string_end = DATEFUNC_stdtimenosec($hour_end, $minute_end);
1178    
1179     $is_restricted = FALSE;
1180     if (strlen($rstdtime_in) >= ($i+1))
1181     {
1182     if (SubStr($rstdtime_in, $i, 1) == "R")
1183     $is_restricted = TRUE;
1184     }
1185    
1186     $rv .= "<input type=\"checkbox\" name=\"";
1187     $rv .= sprintf("rstdtime%02d", $i);
1188     $rv .= "\"";
1189     if ($is_restricted)
1190     $rv .= " checked";
1191     $rv .= ">&nbsp;";
1192     $rv .= $time_string_start . " - " . $time_string_end;
1193     if ($i != 47)
1194     $rv .= "<br>";
1195     }
1196    
1197     return($rv);
1198     }
1199     //--------------------------------------------------------------------------------------------------------------
1200     //Returns the HTML that should be used to identify the schedaheadhrs description on the EDIT and ADD pages.
1201     //HTML may be marked up with <i>, <b>, and <b>.
1202     //
1203     function RSCS_rstdtime_desc_html_01()
1204     {
1205     $rv = "The <i>rstdtime</i> field specifies those half-hour time slots of a 24-hour day during which "
1206     . "a user without permission to break scheduling rules may not reserve a resource.&nbsp; This field "
1207     . "is intended to prevent students and aircraft renters from reserving flight instructors at times "
1208     . "of the day during which they do not desire to teach or aircraft during times of the day when they "
1209     . "are not available for rental.";
1210    
1211     return($rv);
1212     }
1213     //--------------------------------------------------------------------------------------------------------------
1214     //--------------------------------------------------------------------------------------------------------------
1215     //Returns the HTML that should be used to identify the password on the EDIT and ADD pages. HTML may
1216     //be marked up with <i> and <b> and includes the trailing colon.
1217     //
1218     function RSCS_password_id_html_01($curuserinfo_in)
1219     {
1220     return("<i>Password for user <b>" . $curuserinfo_in["userid"] . "</b>:</i>");
1221     }
1222     //--------------------------------------------------------------------------------------------------------------
1223     //Returns the HTML that should be used to display the rstdtime form field on the EDIT and ADD pages.
1224     //
1225     function RSCS_password_disp_html_01()
1226     {
1227     return("<input type=\"password\" name=\"password\" size=\"20\">");
1228     }
1229     //--------------------------------------------------------------------------------------------------------------
1230     //Returns the HTML that should be used to identify the schedaheadhrs description on the EDIT and ADD pages.
1231     //HTML may be marked up with <i>, <b>, and <b>.
1232     //
1233     function RSCS_password_desc_html_01()
1234     {
1235     $rv = "The <i>password</i> field is used to verify that the logged-in user is actually the individual "
1236     . "attempting to make this change.&nbsp; This is an attempt to guard against data modification or "
1237     . "destruction due to unattended computers.&nbsp; If the password entered is incorrect, the user "
1238     . "will be automatically logged out.";
1239    
1240     return($rv);
1241     }
1242     //--------------------------------------------------------------------------------------------------------------
1243     //--------------------------------------------------------------------------------------------------------------
1244     function RSCS_idx_validate_a(
1245     $field_val_in, //Value to be considered.
1246     $action_in, //"A" for add or "M" for modify.
1247     &$field_val_out, //May be sanitized.
1248     &$errors_out, //Appended errors.
1249     &$warnings_out //Appended warnings
1250     )
1251     {
1252     //Restrict the field value in to just digits.
1253     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, "0123456789", 12);
1254    
1255     //See if can pack it into an integer. Errors create "0", which will fail as a commit
1256     //attempt.
1257     if (is_numeric($field_val_in))
1258     {
1259     $field_val_in = (int)$field_val_in;
1260     if ($field_val_in < 0)
1261     $field_val_in = 0;
1262     }
1263     else
1264     {
1265     $field_val_in = 0;
1266     }
1267    
1268     //If the value is 0, this is suspicious.
1269     if ($field_val_in == 0)
1270     {
1271     $errors_out[] = "The <i>idx</i> field is not a valid integer index.";
1272     }
1273    
1274     //Return the sanitized output.
1275     $field_val_out = (string)$field_val_in;
1276     }
1277     //--------------------------------------------------------------------------------------------------------------
1278     function RSCS_type_validate_a(
1279     $field_val_in, //Value to be considered.
1280     $action_in, //"A" for add or "M" for modify.
1281     &$field_val_out, //May be sanitized.
1282     &$errors_out, //Appended errors.
1283     &$warnings_out //Appended warnings
1284     )
1285     {
1286     //Restrict the field value in to just one digit.
1287     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, "0123456789", 1);
1288    
1289     //See if can pack it into an integer. Errors create "-1", which will fail as a commit
1290     //attempt.
1291     if (is_numeric($field_val_in))
1292     {
1293     $field_val_in = (int)$field_val_in;
1294     if ($field_val_in < 0)
1295     $field_val_in = -1;
1296     }
1297     else
1298     {
1299     $field_val_in = -1;
1300     }
1301    
1302     //If the value is -1, this is suspicious.
1303     if ($field_val_in == -1)
1304     {
1305     $errors_out[] = "The <i>type</i> field is not a valid integer type.";
1306     }
1307     else if (
1308     ($field_val_in != RSCS_TYPE_AIRCRAFT)
1309     &&
1310     ($field_val_in != RSCS_TYPE_SIMULATOR)
1311     &&
1312     ($field_val_in != RSCS_TYPE_FLIGHTINSTRUCTOR)
1313     )
1314     {
1315     //This isn't an allowed value.
1316     $errors_out[] = "The <i>type</i> field is not a valid type (aircraft, simulator, or flight instructor).";
1317     }
1318    
1319     //Return the sanitized output.
1320     $field_val_out = (string)$field_val_in;
1321     }
1322     //--------------------------------------------------------------------------------------------------------------
1323     function RSCS_status_validate_a(
1324     $field_val_in, //Value to be considered.
1325     $action_in, //"A" for add or "M" for modify.
1326     &$field_val_out, //May be sanitized.
1327     &$errors_out, //Appended errors.
1328     &$warnings_out //Appended warnings
1329     )
1330     {
1331     //Restrict the field value in to just one digit.
1332     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, "0123456789", 1);
1333    
1334     //See if can pack it into an integer. Errors create "-1", which will fail as a commit
1335     //attempt.
1336     if (is_numeric($field_val_in))
1337     {
1338     $field_val_in = (int)$field_val_in;
1339     if ($field_val_in < 0)
1340     $field_val_in = -1;
1341     }
1342     else
1343     {
1344     $field_val_in = -1;
1345     }
1346    
1347     //If the value is -1, this is suspicious.
1348     if ($field_val_in == -1)
1349     {
1350     $errors_out[] = "The <i>status</i> field is not a valid integer.";
1351     }
1352     else if (
1353     ($field_val_in != RSCS_STATUS_OFFLINE)
1354     &&
1355     ($field_val_in != RSCS_STATUS_ONLINE)
1356     )
1357     {
1358     //This isn't an allowed value.
1359     $errors_out[] = "The <i>status</i> field is not a valid integer (offline or online).";
1360     }
1361    
1362     //Return the sanitized output.
1363     $field_val_out = (string)$field_val_in;
1364     }
1365     //--------------------------------------------------------------------------------------------------------------
1366     function RSCS_disporder_validate_a(
1367     $field_val_in, //Value to be considered.
1368     $action_in, //"A" for add or "M" for modify.
1369     &$field_val_out, //May be sanitized.
1370     &$errors_out, //Appended errors.
1371     &$warnings_out //Appended warnings
1372     )
1373     {
1374     //Restrict the field value in to 12 digits.
1375     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, "0123456789", 12);
1376    
1377     //See if can pack it into an integer. Errors create "0", which is acceptable for disporder.
1378     if (is_numeric($field_val_in))
1379     {
1380     $field_val_in = (int)$field_val_in;
1381     if ($field_val_in <= 0)
1382     $field_val_in = -1;
1383     }
1384     else
1385     {
1386     $field_val_in = -1;
1387     }
1388    
1389     //If the value is -1, this means an error was encountered.
1390     if ($field_val_in == -1)
1391     {
1392     $errors_out[] = "The <i>disporder</i> field is not a valid positive integer.";
1393     $field_val_in = 1;
1394     }
1395    
1396     //Return the sanitized output.
1397     $field_val_out = (string)$field_val_in;
1398     }
1399     //--------------------------------------------------------------------------------------------------------------
1400     function RSCS_initials_validate_a(
1401     $field_val_in, //Value to be considered.
1402     $action_in, //"A" for add or "M" for modify.
1403     &$field_val_out, //May be sanitized.
1404     &$errors_out, //Appended errors.
1405     &$warnings_out //Appended warnings
1406     )
1407     {
1408     //Restrict the field value in a set of characters and to 25 characters.
1409     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, RSCS_INITIALS_ALLOWEDCHARS, 25);
1410    
1411     //Trim both sides.
1412     $field_val_in = Trim($field_val_in);
1413    
1414     //The only error is if this is zero length.
1415     if (strlen($field_val_in) == 0)
1416     {
1417     $errors_out[] = "The <i>initials</i> field may not be left blank.";
1418     }
1419    
1420     //Return the sanitized output.
1421     $field_val_out = (string)$field_val_in;
1422     }
1423     //--------------------------------------------------------------------------------------------------------------
1424     function RSCS_shortdesc_validate_a(
1425     $field_val_in, //Value to be considered.
1426     $action_in, //"A" for add or "M" for modify.
1427     &$field_val_out, //May be sanitized.
1428     &$errors_out, //Appended errors.
1429     &$warnings_out //Appended warnings
1430     )
1431     {
1432     //Restrict the field value in a set of characters and to 50 characters.
1433     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, RSCS_SHORTDESC_ALLOWEDCHARS, 50);
1434    
1435     //Trim both sides.
1436     $field_val_in = Trim($field_val_in);
1437    
1438     //The only error is if this is zero length.
1439     if (strlen($field_val_in) == 0)
1440     {
1441     $errors_out[] = "The <i>shortdesc</i> field may not be left blank.";
1442     }
1443    
1444     //Return the sanitized output.
1445     $field_val_out = (string)$field_val_in;
1446     }
1447     //--------------------------------------------------------------------------------------------------------------
1448     function RSCS_longdesc_validate_a(
1449     $field_val_in, //Value to be considered.
1450     $action_in, //"A" for add or "M" for modify.
1451     &$field_val_out, //May be sanitized.
1452     &$errors_out, //Appended errors.
1453     &$warnings_out //Appended warnings
1454     )
1455     {
1456     //Restrict the field value in a set of characters and to 100 characters.
1457     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, RSCS_LONGDESC_ALLOWEDCHARS, 100);
1458    
1459     //Trim both sides.
1460     $field_val_in = Trim($field_val_in);
1461    
1462     //The only error is if this is zero length.
1463     if (strlen($field_val_in) == 0)
1464     {
1465     $errors_out[] = "The <i>longdesc</i> field may not be left blank.";
1466     }
1467    
1468     //Return the sanitized output.
1469     $field_val_out = (string)$field_val_in;
1470     }
1471     //--------------------------------------------------------------------------------------------------------------
1472     function RSCS_schedaheadhrs_validate_a(
1473     $field_val_in, //Value to be considered.
1474     $action_in, //"A" for add or "M" for modify.
1475     &$field_val_out, //May be sanitized.
1476     &$errors_out, //Appended errors.
1477     &$warnings_out //Appended warnings
1478     )
1479     {
1480     //Restrict the field value in to 12 digits.
1481     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, "0123456789", 12);
1482    
1483     //See if can pack it into an integer. Errors create "0", which is acceptable for schedaheadhrs.
1484     if (is_numeric($field_val_in))
1485     {
1486     $field_val_in = (int)$field_val_in;
1487     if ($field_val_in < 0)
1488     $field_val_in = -1;
1489     }
1490     else
1491     {
1492     $field_val_in = -1;
1493     }
1494    
1495     //If the value is -1, this means an error was encountered.
1496     if ($field_val_in == -1)
1497     {
1498     $errors_out[] = "The <i>schedaheadhrs</i> field is not a valid non-negative integer.";
1499     $field_val_in = 0;
1500     }
1501    
1502     //Return the sanitized output.
1503     $field_val_out = (string)$field_val_in;
1504     }
1505     //--------------------------------------------------------------------------------------------------------------
1506     function RSCS_usercorres_validate_a(
1507     $field_val_in, //Value to be considered.
1508     $action_in, //"A" for add or "M" for modify.
1509     &$field_val_out, //May be sanitized.
1510     &$errors_out, //Appended errors.
1511     &$warnings_out //Appended warnings
1512     )
1513     {
1514     //Restrict the field value in a set of characters and to 20 characters.
1515     $field_val_in = STRFUNC_force_stringtype_subset_truncate($field_val_in, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 20);
1516    
1517     //Force the upper-case elements of the string to lower-case.
1518     $field_val_in = StrToLower($field_val_in);
1519    
1520     if (strlen($field_val_in) == 0)
1521     {
1522     //The string length seems to be zero. This may be a synonym for "no linked user". Just
1523     //say "0".
1524     $field_val_out = "0";
1525     return;
1526     }
1527     else if ($field_val_in == "0")
1528     {
1529     //"0".
1530     $field_val_out = "0";
1531     return;
1532     }
1533     else
1534     {
1535     if (! USRS_userid_membership_test($field_val_in))
1536     {
1537     $errors_out[] = "The <i>usercorres</i> cannot be parsed.";
1538     $field_val_out = "0";
1539     return;
1540     }
1541    
1542     //See if this is a user.
1543     $result = USRS_userid_idx_map($field_val_in);
1544     if ($result === FALSE)
1545     {
1546     //No such user can be found. This is an error.
1547     $errors_out[] = "The <i>usercorres</i> user <i>" . $field_val_in . "</i> does not exist.";
1548     $field_val_out = "0";
1549     return;
1550     }
1551     else
1552     {
1553     //User found.
1554     $field_val_out = (string)$result;
1555     return;
1556     }
1557     }
1558     }
1559     //--------------------------------------------------------------------------------------------------------------
1560     //Given a comma-separated list of integers (direct from the schedalonerscs), and an associative array
1561     //of resources indexed by idx then field, creates a comma-separated list of short descriptors. Used to format resources
1562     //for display of what each user is allowed to rent without an instructor. Any indices that don't correspond
1563     //to resources are just ignored.
1564     //
1565     function RSCS_csl_to_short_rscs_list_a($csl_in, $rscs_in)
1566     {
1567     //If the resource list is non-existent, can't do much, anyway.
1568     if ($rscs_in === FALSE)
1569     return("");
1570    
1571     $exploded_list = CSL_csl_to_string_array($csl_in);
1572    
1573     if ($exploded_list === FALSE)
1574     {
1575     return("");
1576     }
1577    
1578     $rv = "";
1579    
1580     for ($i=0; $i<count($exploded_list); $i++)
1581     {
1582     $index = (int)$exploded_list[$i];
1583    
1584     if (isset($rscs_in[$index]["initials"]))
1585     {
1586     $rv = $rv
1587     . $rscs_in[$index]["initials"]
1588     . ", ";
1589     }
1590     }
1591    
1592     //If we're here, we just need to remove the final two characters.
1593     $rv = SubStr($rv, 0, strlen($rv) - 2);
1594    
1595     return($rv);
1596     }
1597     //
1598     //--------------------------------------------------------------------------------------------------------------
1599     //End of $RCSfile: rscsx.inc,v $.
1600     //--------------------------------------------------------------------------------------------------------------
1601     ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25