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

Contents of /to_be_filed/webprojs/php_libraries/php_library/fboprime/usrsx.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 5 months ago) by dashley
File size: 46343 byte(s)
Initial commit.
1 <?php
2 //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/fboprime/sw/phplib/usrsx.inc,v 1.12 2006/11/05 21:23:55 dashley Exp $
3 //--------------------------------------------------------------------------------------------------------------
4 //usrsx.inc--FboPrime Database usrs Table Manipulation Functions (Not Scheduler Critical)
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 //Contains functions related to [operations on] the usrs table of the database that
22 //aren't necessary for the operation of the dayview scheduler.
23 //--------------------------------------------------------------------------------------------------------------
24 //
25 require_once("config.inc");
26 require_once("dbx.inc");
27 require_once("global.inc");
28 require_once("sguid.inc");
29 require_once("usrs.inc");
30 //
31 //--------------------------------------------------------------------------------------------------------------
32 //Retrieves key information about active users, ordered by:
33 // a)Last name.
34 // b)First name.
35 // c)Middle Initial.
36 // d)Database index (the decisive tie breaker).
37 //
38 //This information is displayed on the active users list page.
39 //
40 //Although there is some minor risk of memory exhaustion, it is too slow to grab only the indices
41 //and then yank the info as the table is generated.
42 //
43 //Returns FALSE if no records.
44 //
45 function USRS_get_info_users_active_a()
46 {
47 global $GLOBAL_dbhandle;
48
49 //Form the query string.
50 $query_string = "SELECT idx,fname,lname,mname,userid,mostrecentlogin,acctexpdate,schedalonerscs FROM usrs WHERE status=\""
51 .
52 USRS_STATUS_ACTIVE
53 .
54 "\" ORDER BY lname ASC, fname ASC, mname ASC, idx ASC";
55
56 //Execute the query.
57 $result = mysql_query($query_string, $GLOBAL_dbhandle);
58
59 if ($result === FALSE)
60 {
61 //Unknown query failure. Return FALSE to the caller. No need to free,
62 //as this is not a result.
63 $rv = FALSE;
64 }
65 else
66 {
67 //Figure out how many rows in the result.
68 $nrows = mysql_num_rows($result);
69
70 if ($nrows == 0)
71 {
72 //No rows in the result. The query failed to give us a record, but still
73 //we need to free the result set.
74
75 //Free the result.
76 mysql_free_result($result);
77
78 //The caller gets FALSE. No records.
79 $rv = FALSE;
80 }
81 else
82 {
83 //We have at least one record. Grab the indices.
84 //
85 for ($i=0; $i<$nrows; $i++)
86 {
87 $temp = mysql_fetch_assoc($result);
88 $rv[$i] = $temp;
89 }
90
91 //Free the result.
92 mysql_free_result($result);
93 }
94
95 //Return the value to the caller.
96 return($rv);
97 }
98 }
99 //
100 //--------------------------------------------------------------------------------------------------------------
101 //Retrieves key information about inactive users, ordered by:
102 // a)Last name.
103 // b)First name.
104 // c)Middle Initial.
105 // d)Database index (the decisive tie breaker).
106 //
107 //This information is displayed on the inactive users list page.
108 //
109 //Although there is some minor risk of memory exhaustion, it is too slow to grab only the indices
110 //and then yank the info as the table is generated.
111 //
112 //Returns FALSE if no records.
113 //
114 function USRS_get_info_users_inactive_a()
115 {
116 global $GLOBAL_dbhandle;
117
118 //Form the query string.
119 $query_string = "SELECT idx,fname,lname,mname,userid,mostrecentlogin,acctexpdate,schedalonerscs FROM usrs WHERE status=\""
120 .
121 USRS_STATUS_INACTIVE
122 .
123 "\" ORDER BY lname ASC, fname ASC, mname ASC, idx ASC";
124
125 //Execute the query.
126 $result = mysql_query($query_string, $GLOBAL_dbhandle);
127
128 if ($result === FALSE)
129 {
130 //Unknown query failure. Return FALSE to the caller. No need to free,
131 //as this is not a result.
132 $rv = FALSE;
133 }
134 else
135 {
136 //Figure out how many rows in the result.
137 $nrows = mysql_num_rows($result);
138
139 if ($nrows == 0)
140 {
141 //No rows in the result. The query failed to give us a record, but still
142 //we need to free the result set.
143
144 //Free the result.
145 mysql_free_result($result);
146
147 //The caller gets FALSE. No records.
148 $rv = FALSE;
149 }
150 else
151 {
152 //We have at least one record. Grab the indices.
153 //
154 for ($i=0; $i<$nrows; $i++)
155 {
156 $temp = mysql_fetch_assoc($result);
157 $rv[$i] = $temp;
158 }
159
160 //Free the result.
161 mysql_free_result($result);
162 }
163
164 //Return the value to the caller.
165 return($rv);
166 }
167 }
168 //
169 //--------------------------------------------------------------------------------------------------------------
170 //Retrieves key information about all users, and populates an array indexed by the database index with this
171 //information. If there are no users, FALSE is returned.
172 //
173 function USRS_get_info_users_all_a()
174 {
175 global $GLOBAL_dbhandle;
176
177 //Form the query string.
178 $query_string = "SELECT idx,fname,mname,lname FROM usrs";
179
180 //Execute the query.
181 $result = mysql_query($query_string, $GLOBAL_dbhandle);
182
183 if ($result === FALSE)
184 {
185 //Unknown query failure. Return FALSE to the caller. No need to free,
186 //as this is not a result.
187 $rv = FALSE;
188 }
189 else
190 {
191 //Figure out how many rows in the result.
192 $nrows = mysql_num_rows($result);
193
194 if ($nrows == 0)
195 {
196 //No rows in the result. The query failed to give us a record, but still
197 //we need to free the result set.
198
199 //Free the result.
200 mysql_free_result($result);
201
202 //The caller gets FALSE. No records.
203 $rv = FALSE;
204 }
205 else
206 {
207 //We have at least one record. Grab the indices.
208 //
209 for ($i=0; $i<$nrows; $i++)
210 {
211 $temp = mysql_fetch_assoc($result);
212 $rv[$temp["idx"]] = $temp;
213 }
214
215 //Free the result.
216 mysql_free_result($result);
217 }
218
219 //Return the value to the caller.
220 return($rv);
221 }
222 }
223 //
224 //--------------------------------------------------------------------------------------------------------------
225 //Given a user's first name, middle name or intitial, and last name, forms a name
226 //string. This is used for the users lists.
227 //
228 function USRS_display_name_string($fname_in, $mname_in, $lname_in)
229 {
230 $fnl = strlen($fname_in);
231 $mnl = strlen($mname_in);
232 $lnl = strlen($lname_in);
233
234 if (!$lnl)
235 {
236 //This is a no-no.
237 return("UNKNOWN USER");
238 }
239 else if ($lnl && !$fnl)
240 {
241 return($lname_in);
242 }
243 else
244 {
245 if ($mnl)
246 {
247 return($lname_in . ", " . $fname_in . " " . SubStr($mname_in, 0, 1) . ".");
248 }
249 else
250 {
251 return($lname_in . ", " . $fname_in);
252 }
253 }
254 }
255 //--------------------------------------------------------------------------------------------------------------
256 //Stuffs the pwhash field of a usrs record by index. There is
257 //no result code. The temporary password is destroyed at the same time.
258 //
259 //This operation is considered exempt from the modification SGUID checks--the password
260 //is a separate matter and not part of the normal field edits.
261 //
262 function USRS_pwhash_stuff($idx_in, $pwhash_in)
263 {
264 global $GLOBAL_dbhandle;
265
266 //Set the password hash with a single SQL statement.
267 $query_string = "UPDATE usrs SET pwhash=\"" . $pwhash_in . "\", lostpwhash=\"\", lostpwgentime=\"\" WHERE idx=\"" . $idx_in . "\"";
268
269 //Run the query. We don't much care whether it fails or succeeds (nothing to be done, anyway).
270 mysql_query($query_string, $GLOBAL_dbhandle);
271 }
272 //
273 //--------------------------------------------------------------------------------------------------------------
274 //Description
275 // Adds or modifies a USRS record. Certain parameters specify what is expected.
276 //
277 //Inputs
278 // action_in
279 // Enumerated type. Possibilities are:
280 // "A" : Add new.
281 // "M" : Modify existing.
282 //
283 // rec_in
284 // The data about the record to add or modify, as an associative array.
285 //
286 // Adding a record:
287 // a)The index must be absent (it is assigned automatically by the database).
288 // b)The userid must be included and must be globally unique, otherwise an error will be
289 // returned and the record won't be added.
290 // c)Fields out of range or defective will be corrected, and warnings will be returned.
291 // The record will, however, be added if possible.
292 // c)All fields not present in the associative array will be assigned default values.
293 // d)The creation/modification SGUID is handled automatically and may not be included in the
294 // associative array.
295 //
296 // Modifying a record:
297 // a)The record is specified by either index or userid. If both are specified, they must
298 // correspond to an existing record and must be consistent.
299 // b)Fields not included in the associative array are not touched.
300 // c)The creation/modification SGUID is handled automatically. If this field is included
301 // in the associative array, it means to check this against what is in the database
302 // and error out on editing collision if the value doesn't match what is in the database.
303 //
304 //Outputs
305 // result_code_out
306 // Adding a record:
307 // 0 if the operation failed, or the index if it succeeded.
308 // Modifying an existing record.
309 // 0 if the operation failed or 1 if it succeeds.
310 //
311 // errors_out
312 // If any errors resulted, an associative array of integers specifying the errors per the defined
313 // constants, or FALSE otherwise.
314 //
315 // warnings_out
316 // If any warnings resulted, an associative array of integers specifying the warnings per the
317 // defined constants, or FALSE otherwise.
318 //
319 //Database Locking
320 // Locking is performed per the recursive method described in the documentation. If, for example,
321 // the client wishes to call this function from within a larger critical section, as long as the
322 // client uses the recursive locking method, everything will operate correctly.
323 //
324 function USRS_record_add_modify($action_in, $rec_in, &$result_code_out, &$errors_out, &$warnings_out)
325 {
326 global $GLOBAL_dbhandle;
327 global $GLOBAL_dblocked;
328 global $CONFIG_FBO_USER_CATEGORIES;
329
330 //Variable remembers if are terminating the function (i.e. something fatal has been
331 //encountered).
332 $in_termination_sequence = FALSE;
333
334 //Error array and warnings array start at element 0.
335 //
336 $e_array_idx = 0;
337 $w_array_idx = 0;
338
339 //Take a look at the action. It must be one of the two valid codes, "A" or "M".
340 //
341 if (!$in_termination_sequence)
342 {
343 if (($action_in != "A") && ($action_in != "M"))
344 {
345 $errors_out_local[$e_array_idx] = USRS_ERROR_ACTION_PAR_ILLEGAL;
346 $e_array_idx++;
347 $in_termination_sequence = TRUE;
348 }
349 }
350
351 //Take a look at the index. If it is present, it must be a positive integer or the
352 //string equivalent of a positive integer.
353 //
354 if (!$in_termination_sequence)
355 {
356 if (isset($rec_in["idx"]))
357 {
358 if (DB_table_index_short_validity_check_zna($rec_in["idx"]))
359 {
360 //The variable is logically an integer, and the function said it was
361 //in the valid range. If it is an integer, leave it alone, otherwise
362 //convert it to an integer.
363 //
364 if (!is_int($rec_in["idx"]))
365 {
366 $rec_in["idx"] = intval($rec_in["idx"]);
367 }
368 }
369 else
370 {
371 //The value isn't an integer and can't be converted to an integer.
372 //Error out.
373 $errors_out_local[$e_array_idx] = USRS_ERROR_IDX_ILLEGAL;
374 $e_array_idx++;
375 $in_termination_sequence = TRUE;
376 }
377 }
378 }
379
380 //Take a look at the userid. If that is present, it has to be sane.
381 //
382 if (!$in_termination_sequence)
383 {
384 if (isset($rec_in["userid"]))
385 {
386 //Canonically, the userid has to be all lower-case and can't
387 //contain any extra padding. If it ain't a string, it will
388 //be flagged as an error a few lines down by the membership test
389 //function.
390 //
391 if (is_string($rec_in["userid"]))
392 {
393 $rec_in["userid"] = StrToLower(Trim($rec_in["userid"]));
394 }
395
396 if (USRS_userid_membership_test($rec_in["userid"]) === TRUE)
397 {
398 //The userid is fine.
399 //
400 }
401 else
402 {
403 //The userid is illegal.
404 //
405 $errors_out_local[$e_array_idx] = USRS_ERROR_USERID_ILLEGAL;
406 $e_array_idx++;
407 $in_termination_sequence = TRUE;
408 }
409 }
410 }
411
412 //-----------------------------------------------------------
413 //TODO: Add code to confine and error-trap the other fields.
414 //-----------------------------------------------------------
415
416 if (!$in_termination_sequence)
417 {
418 //Lock the database using the recursive critical section method (discussed in the
419 //manual). This is necessary because the test for presence and the insert have to
420 //be combined atomically.
421 $db_was_locked = $GLOBAL_dblocked;
422 if (! $GLOBAL_dblocked)
423 {
424 DB_db_lock();
425 $GLOBAL_dblocked = TRUE;
426 }
427
428 if ($action_in == "A")
429 {
430 if (isset($rec_in["idx"]))
431 {
432 //This is an error because the index is assigned automatically--it isn't
433 //allowed to specify it.
434 //
435 $errors_out_local[$e_array_idx] = USRS_ERROR_IDX_ON_ADD;
436 $e_array_idx++;
437 $in_termination_sequence = TRUE;
438 }
439 else if (!isset($rec_in["userid"]))
440 {
441 //The userid has to be present on an add. Note that it is checked
442 //for validity if it is present above.
443 //
444 $errors_out_local[$e_array_idx] = USRS_ERROR_NO_USERID_ON_ADD;
445 $e_array_idx++;
446 $in_termination_sequence = TRUE;
447 }
448 else if (USRS_userid_idx_map($rec_in["userid"]) !== FALSE)
449 {
450 //The userid already exists ... illegal.
451 //
452 $errors_out_local[$e_array_idx] = USRS_ERROR_DUP_USERID_ON_ADD;
453 $e_array_idx++;
454 $in_termination_sequence = TRUE;
455 }
456 }
457 else //action is modify
458 {
459 //If the index is present, try to get the record with the passed
460 //index. If not present, error.
461 //
462 if (isset($rec_in["idx"]))
463 {
464 $modify_rec = USRS_retrieve_by_userid($rec_in["idx"]);
465
466 if ($modify_rec === FALSE)
467 {
468 //Rec with that idx does not exist.
469 //
470 $errors_out_local[$e_array_idx] = USRS_ERROR_MOD_REC_NOT_PRESENT;
471 $e_array_idx++;
472 $in_termination_sequence = TRUE;
473 }
474 else //Record was found by index.
475 {
476 //Check to be sure userid, if it exists, is consistent.
477 if (isset($rec_in["userid"]))
478 {
479 if ($rec_in["userid"] != $modify_rec["userid"])
480 {
481 //On modification, index and userid do not match.
482 //
483 $errors_out_local[$e_array_idx] = USRS_ERROR_MOD_IDX_USERID_INCONSISTENT;
484 $e_array_idx++;
485 $in_termination_sequence = TRUE;
486 }
487 }
488 }
489 }
490 else if (isset($rec_in["userid"]))
491 {
492 //The userid was specified, but not the idx. Check to be sure that record exists,
493 //if not, error out, if so, keep track of the index.
494 //
495 $modify_rec = USRS_userid_idx_map($rec_in["userid"]);
496
497 if ($modify_rec === FALSE)
498 {
499 //The userid does not exist. Can't identify this record to modify.
500 //Error out.
501 //
502 $errors_out_local[$e_array_idx] = USRS_ERROR_MOD_REC_NOT_PRESENT;
503 $e_array_idx++;
504 $in_termination_sequence = TRUE;
505 }
506 else
507 {
508 //The record corresponding to the userid does exist. Stuff the
509 //index to save us time later.
510 //
511 $rec_in["idx"] = $modify_rec["idx"];
512 }
513 }
514 else
515 {
516 //There isn't enough information to identify the record to modify (no idx,
517 //no userid). Have to error out.
518 //
519 $errors_out_local[$e_array_idx] = USRS_ERROR_MOD_REC_NOT_PRESENT;
520 $e_array_idx++;
521 $in_termination_sequence = TRUE;
522 }
523 }
524
525 //If the command is to modify, look for an editing collision.
526 //
527 if (!$in_termination_sequence)
528 {
529 if ($action_in == "M")
530 {
531 if ($rec_in["crmodsguid"] != $modify_rec["crmodsguid"])
532 {
533 $errors_out_local[$e_array_idx] = USRS_ERROR_EDITING_COLLISION;
534 $e_array_idx++;
535 $in_termination_sequence = TRUE;
536 }
537 }
538 }
539
540 //Form the query strings. There are two different types, depending on whether
541 //we are adding or modifying a record.
542 //
543 //For adding, the string will be of the form:
544 // INSERT INTO usrs SET fn1=val1, fn2=val2, etc.
545 //
546 //For modifying, the string will be of the form:
547 // UPDATE usrs SET fn1=val1, fn2=val2, etc. WHERE idx=val.
548 //
549 if (!$in_termination_sequence)
550 {
551 //Obtain an SGUID to for the create/modification stamp.
552 //
553 $crmodsguid = SGUID_sguid();
554
555 if ($action_in == "A")
556 {
557 //Add
558 //
559 $query_string = "INSERT INTO usrs SET status=\"";
560 //
561 //-----------------------------------------------------------------------------------------
562 //status
563 //-----------------------------------------------------------------------------------------
564 if (isset($rec_in["status"]))
565 {
566 $query_string .= mysql_real_escape_string((string)$rec_in["status"], $GLOBAL_dbhandle);
567 }
568 else
569 {
570 $query_string .= mysql_real_escape_string((string)USRS_STATUS_ACTIVE, $GLOBAL_dbhandle);
571 }
572 $query_string .= "\", seclvl=\"";
573 //
574 //-----------------------------------------------------------------------------------------
575 //seclvl
576 //-----------------------------------------------------------------------------------------
577 if (isset($rec_in["seclvl"]))
578 {
579 $query_string .= mysql_real_escape_string((string)$rec_in["seclvl"], $GLOBAL_dbhandle);
580 }
581 else
582 {
583 //Expression below gets last entry from the lookup table.
584 //
585 $query_string .= mysql_real_escape_string((string)($CONFIG_FBO_USER_CATEGORIES[count($CONFIG_FBO_USER_CATEGORIES) - 4]),
586 $GLOBAL_dbhandle);
587 }
588 $query_string .= "\", userid=\"";
589 //
590 //-----------------------------------------------------------------------------------------
591 //userid (this field is mandatory)
592 //-----------------------------------------------------------------------------------------
593 $query_string .= mysql_real_escape_string((string)$rec_in["userid"], $GLOBAL_dbhandle);
594 $query_string .= "\", role=\"";
595 //
596 //-----------------------------------------------------------------------------------------
597 //role
598 //-----------------------------------------------------------------------------------------
599 if (isset($rec_in["role"]))
600 {
601 $query_string .= mysql_real_escape_string((string)$rec_in["role"], $GLOBAL_dbhandle);
602 }
603 else
604 {
605 $query_string .= mysql_real_escape_string((string)USRS_ROLE_CUSTNONPILOT, $GLOBAL_dbhandle);
606 }
607 $query_string .= "\", perm=\"";
608 //
609 //-----------------------------------------------------------------------------------------
610 //perm
611 //-----------------------------------------------------------------------------------------
612 if (isset($rec_in["perm"]))
613 {
614 $query_string .= mysql_real_escape_string($rec_in["perm"], $GLOBAL_dbhandle);
615 }
616 else
617 {
618 $query_string .= mysql_real_escape_string("", $GLOBAL_dbhandle);
619 }
620 $query_string .= "\", sex=\"";
621 //
622 //-----------------------------------------------------------------------------------------
623 //sex
624 //-----------------------------------------------------------------------------------------
625 if (isset($rec_in["sex"]))
626 {
627 $query_string .= mysql_real_escape_string((string)$rec_in["sex"], $GLOBAL_dbhandle);
628 }
629 else
630 {
631 $query_string .= mysql_real_escape_string((string)USRS_SEX_UNSPECIFIED, $GLOBAL_dbhandle);
632 }
633 $query_string .= "\", title=\"";
634 //
635 //-----------------------------------------------------------------------------------------
636 //title
637 //-----------------------------------------------------------------------------------------
638 if (isset($rec_in["title"]))
639 {
640 $query_string .= mysql_real_escape_string((string)$rec_in["title"], $GLOBAL_dbhandle);
641 }
642 else
643 {
644 //Empty string.
645 }
646 $query_string .= "\", fname=\"";
647 //
648 //-----------------------------------------------------------------------------------------
649 //fname
650 //-----------------------------------------------------------------------------------------
651 if (isset($rec_in["fname"]))
652 {
653 $query_string .= mysql_real_escape_string((string)$rec_in["fname"], $GLOBAL_dbhandle);
654 }
655 else
656 {
657 //Empty string.
658 }
659 $query_string .= "\", mname=\"";
660 //
661 //-----------------------------------------------------------------------------------------
662 //mname
663 //-----------------------------------------------------------------------------------------
664 if (isset($rec_in["mname"]))
665 {
666 $query_string .= mysql_real_escape_string((string)$rec_in["mname"], $GLOBAL_dbhandle);
667 }
668 else
669 {
670 //Empty string.
671 }
672 $query_string .= "\", lname=\"";
673 //
674 //-----------------------------------------------------------------------------------------
675 //lname
676 //-----------------------------------------------------------------------------------------
677 if (isset($rec_in["lname"]))
678 {
679 $query_string .= mysql_real_escape_string((string)$rec_in["lname"], $GLOBAL_dbhandle);
680 }
681 else
682 {
683 //Empty string.
684 }
685 $query_string .= "\", suffix=\"";
686 //
687 //-----------------------------------------------------------------------------------------
688 //suffix
689 //-----------------------------------------------------------------------------------------
690 if (isset($rec_in["suffix"]))
691 {
692 $query_string .= mysql_real_escape_string((string)$rec_in["suffix"], $GLOBAL_dbhandle);
693 }
694 else
695 {
696 //Empty string.
697 }
698 $query_string .= "\", adl1=\"";
699 //
700 //-----------------------------------------------------------------------------------------
701 //adl1
702 //-----------------------------------------------------------------------------------------
703 if (isset($rec_in["adl1"]))
704 {
705 $query_string .= mysql_real_escape_string((string)$rec_in["adl1"], $GLOBAL_dbhandle);
706 }
707 else
708 {
709 //Empty string.
710 }
711 $query_string .= "\", adl2=\"";
712 //
713 //-----------------------------------------------------------------------------------------
714 //adl2
715 //-----------------------------------------------------------------------------------------
716 if (isset($rec_in["adl1"]))
717 {
718 $query_string .= mysql_real_escape_string((string)$rec_in["adl2"], $GLOBAL_dbhandle);
719 }
720 else
721 {
722 //Empty string.
723 }
724 $query_string .= "\", city=\"";
725 //
726 //-----------------------------------------------------------------------------------------
727 //city
728 //-----------------------------------------------------------------------------------------
729 if (isset($rec_in["city"]))
730 {
731 $query_string .= mysql_real_escape_string((string)$rec_in["city"], $GLOBAL_dbhandle);
732 }
733 else
734 {
735 //Empty string.
736 }
737 $query_string .= "\", stateprovince=\"";
738 //
739 //-----------------------------------------------------------------------------------------
740 //stateprovince
741 //-----------------------------------------------------------------------------------------
742 if (isset($rec_in["stateprovince"]))
743 {
744 $query_string .= mysql_real_escape_string((string)$rec_in["stateprovince"], $GLOBAL_dbhandle);
745 }
746 else
747 {
748 //Empty string.
749 }
750 $query_string .= "\", zippostalcode=\"";
751 //
752 //-----------------------------------------------------------------------------------------
753 //zippostalcode
754 //-----------------------------------------------------------------------------------------
755 if (isset($rec_in["zippostalcode"]))
756 {
757 $query_string .= mysql_real_escape_string((string)$rec_in["zippostalcode"], $GLOBAL_dbhandle);
758 }
759 else
760 {
761 //Empty string.
762 }
763 $query_string .= "\", country=\"";
764 //
765 //-----------------------------------------------------------------------------------------
766 //country
767 //-----------------------------------------------------------------------------------------
768 if (isset($rec_in["country"]))
769 {
770 $query_string .= mysql_real_escape_string((string)$rec_in["country"], $GLOBAL_dbhandle);
771 }
772 else
773 {
774 //Empty string.
775 }
776 $query_string .= "\", pwhash=\"";
777 //
778 //-----------------------------------------------------------------------------------------
779 //pwhash
780 //-----------------------------------------------------------------------------------------
781 if (isset($rec_in["pwhash"]))
782 {
783 $query_string .= mysql_real_escape_string((string)$rec_in["pwhash"], $GLOBAL_dbhandle);
784 }
785 else
786 {
787 //Empty string.
788 }
789 $query_string .= "\", lostpwhash=\"";
790 //
791 //-----------------------------------------------------------------------------------------
792 //lostpwhash
793 //-----------------------------------------------------------------------------------------
794 if (isset($rec_in["lostpwhash"]))
795 {
796 $query_string .= mysql_real_escape_string((string)$rec_in["lostpwhash"], $GLOBAL_dbhandle);
797 }
798 else
799 {
800 //Empty string.
801 }
802 $query_string .= "\", lostpwgentime=\"";
803 //
804 //-----------------------------------------------------------------------------------------
805 //lostpwgentime
806 //-----------------------------------------------------------------------------------------
807 if (isset($rec_in["lostpwgentime"]))
808 {
809 $query_string .= mysql_real_escape_string((string)$rec_in["lostpwgentime"], $GLOBAL_dbhandle);
810 }
811 else
812 {
813 //Empty string.
814 }
815 $query_string .= "\", ratings=\"";
816 //
817 //-----------------------------------------------------------------------------------------
818 //ratings
819 //-----------------------------------------------------------------------------------------
820 if (isset($rec_in["ratings"]))
821 {
822 $query_string .= mysql_real_escape_string((string)$rec_in["ratings"], $GLOBAL_dbhandle);
823 }
824 else
825 {
826 //Empty string.
827 }
828 $query_string .= "\", bfrlicexpdate=\"";
829 //
830 //-----------------------------------------------------------------------------------------
831 //bfrlicexpdate
832 //-----------------------------------------------------------------------------------------
833 if (isset($rec_in["bfrlicexpdate"]))
834 {
835 $query_string .= mysql_real_escape_string((string)$rec_in["bfrlicexpdate"], $GLOBAL_dbhandle);
836 }
837 else
838 {
839 //Empty string.
840 }
841 $query_string .= "\", medexpdate=\"";
842 //
843 //-----------------------------------------------------------------------------------------
844 //medexpdate
845 //-----------------------------------------------------------------------------------------
846 if (isset($rec_in["medexpdate"]))
847 {
848 $query_string .= mysql_real_escape_string((string)$rec_in["medexpdate"], $GLOBAL_dbhandle);
849 }
850 else
851 {
852 //Empty string.
853 }
854 $query_string .= "\", restrictions=\"";
855 //
856 //-----------------------------------------------------------------------------------------
857 //restrictions
858 //-----------------------------------------------------------------------------------------
859 if (isset($rec_in["restrictions"]))
860 {
861 $query_string .= mysql_real_escape_string((string)$rec_in["restrictions"], $GLOBAL_dbhandle);
862 }
863 else
864 {
865 //Empty string.
866 }
867 $query_string .= "\", dayphone=\"";
868 //
869 //-----------------------------------------------------------------------------------------
870 //dayphone
871 //-----------------------------------------------------------------------------------------
872 if (isset($rec_in["dayphone"]))
873 {
874 $query_string .= mysql_real_escape_string((string)$rec_in["dayphone"], $GLOBAL_dbhandle);
875 }
876 else
877 {
878 //Empty string.
879 }
880 $query_string .= "\", eveningphone=\"";
881 //
882 //-----------------------------------------------------------------------------------------
883 //eveningphone
884 //-----------------------------------------------------------------------------------------
885 if (isset($rec_in["eveningphone"]))
886 {
887 $query_string .= mysql_real_escape_string((string)$rec_in["eveningphone"], $GLOBAL_dbhandle);
888 }
889 else
890 {
891 //Empty string.
892 }
893 $query_string .= "\", em1=\"";
894 //
895 //-----------------------------------------------------------------------------------------
896 //em1
897 //-----------------------------------------------------------------------------------------
898 if (isset($rec_in["em1"]))
899 {
900 $query_string .= mysql_real_escape_string((string)$rec_in["em1"], $GLOBAL_dbhandle);
901 }
902 else
903 {
904 //Empty string.
905 }
906 $query_string .= "\", em2=\"";
907 //
908 //-----------------------------------------------------------------------------------------
909 //em2
910 //-----------------------------------------------------------------------------------------
911 if (isset($rec_in["em2"]))
912 {
913 $query_string .= mysql_real_escape_string((string)$rec_in["em2"], $GLOBAL_dbhandle);
914 }
915 else
916 {
917 //Empty string.
918 }
919 $query_string .= "\", acctexpdate=\"";
920 //
921 //-----------------------------------------------------------------------------------------
922 //acctexpdate
923 //-----------------------------------------------------------------------------------------
924 if (isset($rec_in["acctexpdate"]))
925 {
926 $query_string .= mysql_real_escape_string((string)$rec_in["acctexpdate"], $GLOBAL_dbhandle);
927 }
928 else
929 {
930 //Empty string.
931 }
932 $query_string .= "\", mostrecentlogin=\"";
933 //
934 //-----------------------------------------------------------------------------------------
935 //mostrecentlogin
936 //-----------------------------------------------------------------------------------------
937 if (isset($rec_in["mostrecentlogin"]))
938 {
939 $query_string .= mysql_real_escape_string((string)$rec_in["mostrecentlogin"], $GLOBAL_dbhandle);
940 }
941 else
942 {
943 //Empty string.
944 }
945 $query_string .= "\", schedalonerscs=\"";
946 //
947 //-----------------------------------------------------------------------------------------
948 //schedalonerscs
949 //-----------------------------------------------------------------------------------------
950 if (isset($rec_in["schedalonerscs"]))
951 {
952 $query_string .= mysql_real_escape_string((string)$rec_in["schedalonerscs"], $GLOBAL_dbhandle);
953 }
954 else
955 {
956 //Empty string.
957 }
958 $query_string .= "\", fboremarks=\"";
959 //
960 //-----------------------------------------------------------------------------------------
961 //fboremarks
962 //-----------------------------------------------------------------------------------------
963 if (isset($rec_in["fboremarks"]))
964 {
965 $query_string .= mysql_real_escape_string((string)$rec_in["fboremarks"], $GLOBAL_dbhandle);
966 }
967 else
968 {
969 //Empty string.
970 }
971 $query_string .= "\", userremarks=\"";
972 //
973 //-----------------------------------------------------------------------------------------
974 //userremarks
975 //-----------------------------------------------------------------------------------------
976 if (isset($rec_in["userremarks"]))
977 {
978 $query_string .= mysql_real_escape_string((string)$rec_in["userremarks"], $GLOBAL_dbhandle);
979 }
980 else
981 {
982 //Empty string.
983 }
984 $query_string .= "\"";
985 //
986 //echo $query_string;
987
988 //Execute the query to insert the record.
989 $result = mysql_query($query_string, $GLOBAL_dbhandle);
990 //
991 //If the insert failed, our caller gets FALSE.
992 if ($result == FALSE)
993 {
994 $result_code_out = -1;
995 }
996 else
997 {
998 //The insert was successful. Figure out the index that was assigned.
999 $result = mysql_query("SELECT LAST_INSERT_ID()");
1000
1001 //If we have a failure, the caller gets FALSE, otherwise the caller gets the
1002 //index.
1003 if ($result === FALSE)
1004 {
1005 $result_code_out = -1;
1006 }
1007 else
1008 {
1009 //Pick apart the result.
1010 $row = mysql_fetch_array($result, MYSQL_NUM);
1011
1012 //Extract the integer.
1013 $result_code_out = $row[0];
1014
1015 //Free the result memory.
1016 mysql_free_result($result);
1017 }
1018 }
1019 }
1020 else
1021 {
1022 //Modify
1023 //
1024 }
1025 }
1026
1027 //Unlock the database (if it was locked) using the recursive critical section
1028 //method.
1029 if (! $db_was_locked)
1030 {
1031 DB_db_unlock();
1032 $GLOBAL_dblocked = FALSE;
1033 }
1034 } //if not in termination sequence.
1035
1036 //-----------------------------------------------------------
1037 //Clean up the output parameters to go back to the caller.
1038 //
1039 if ($in_termination_sequence)
1040 {
1041 $result_code_out = 0;
1042 }
1043 else if ($result_code_out == -1)
1044 {
1045 //Something went wrong with the query. Return 0 as the
1046 //error code.
1047 $result_code_out = 0;
1048 }
1049 else
1050 {
1051 //The result code contains the index of what was added.
1052 }
1053
1054 if (isset($errors_out_local))
1055 {
1056 $errors_out = $errors_out_local;
1057 }
1058 else
1059 {
1060 $errors_out = FALSE;
1061 }
1062
1063 if (isset($warnings_out_local))
1064 {
1065 $warnings_out = $warnings_out_local;
1066 }
1067 else
1068 {
1069 $warnings_out = FALSE;
1070 }
1071 }
1072 //
1073 //--------------------------------------------------------------------------------------------------------------
1074 //E-mails a user by index (meaning sends the e-mail to each of the contact addresses).
1075 //
1076 //Input parameters:
1077 // a)Idx: index of user in the database.
1078 // b)Subject: the subject of the e-mail.
1079 // c)Message: an array of lines containing the body.
1080 //
1081 //Output parameters:
1082 // a)The number of e-mails actually injected (depends on what is in the database).
1083 //
1084 //A notice about automatically-generated e-mail is automatically appended to the e-mail.
1085 //
1086 function USRS_em_notify($idx_in, $subj_in, $msg_in)
1087 {
1088 global $GLOBAL_stime_year;
1089 global $GLOBAL_stime_month;
1090 global $GLOBAL_stime_day;
1091 global $GLOBAL_stime_hour;
1092 global $GLOBAL_stime_minute;
1093 global $GLOBAL_stime_dow;
1094
1095 $rv = 0;
1096
1097 //Form a footer string that explains the origin of the e-mail.
1098 $footer_text = CONFIG_fbo_automail_footer_text();
1099 //Standard footer.
1100
1101 $footer_split = wordwrap($footer_text, CONFIG_FBO_AUTOMAIL_LINELENGTH, "\n");
1102 $footer_array = explode("\n", $footer_split);
1103
1104 //Trim any empty lines from the end of the array. In the actual e-mail, at least
1105 //as viewed using Outlook, there seem to be two empty lines at the end.
1106 //This hasn't cured it. Trivial issue, but may eventually want to figure
1107 //it out.
1108 //
1109 $n = count($footer_array);
1110 if (($n-1) >= 0)
1111 {
1112 if (strlen($footer_array[$n-1]) == 0)
1113 unset($footer_array[$n-1]);
1114 }
1115 if (($n-2) >= 0)
1116 {
1117 if (strlen($footer_array[$n-2]) == 0)
1118 unset($footer_array[$n-2]);
1119 }
1120
1121 $userinfo = USRS_retrieve_by_idx($idx_in);
1122
1123 if ($userinfo !== FALSE)
1124 {
1125 //Form up the message txt block.
1126 //
1127 $msgtext = "";
1128 for ($i=0; $i<count($msg_in); $i++)
1129 {
1130 $msgtext .= $msg_in[$i];
1131 $msgtext .= "\n";
1132 }
1133
1134 for ($i=0; $i<count($footer_array); $i++)
1135 {
1136 $msgtext .= $footer_array[$i];
1137 if ($i < (count($footer_array) - 1))
1138 $msgtext .= "\n";
1139 }
1140
1141 //Form and send the mail to em1.
1142 if (strlen($userinfo["em1"]))
1143 {
1144 mail(
1145 $userinfo["em1"],
1146 $subj_in,
1147 $msgtext,
1148 "From: " . CONFIG_FBO_AUTOMAIL_FROM . "\r\n" . "Reply-To: " . CONFIG_FBO_AUTOMAIL_FROM
1149 );
1150
1151 $rv++;
1152 }
1153
1154 //Form and send the mail to em2.
1155 if (strlen($userinfo["em2"]))
1156 {
1157 mail(
1158 $userinfo["em2"],
1159 $subj_in,
1160 $msgtext,
1161 "From: " . CONFIG_FBO_AUTOMAIL_FROM . "\r\n" . "Reply-To: " . CONFIG_FBO_AUTOMAIL_FROM
1162 );
1163
1164 $rv++;
1165 }
1166 }
1167
1168 return($rv);
1169 }
1170 //
1171 //--------------------------------------------------------------------------------------------------------------
1172 //Retrieves an array containing the indices of all flight instructors in the resources
1173 //table that are online, or FALSE if none exist.
1174 //
1175 function USRS_get_user_online_idxs()
1176 {
1177 global $GLOBAL_dbhandle;
1178
1179 //Form the query string.
1180 $query_string = "SELECT idx FROM usrs WHERE status=\""
1181 .
1182 mysql_real_escape_string((string)USRS_STATUS_ACTIVE, $GLOBAL_dbhandle)
1183 .
1184 "\"";
1185
1186 //Execute the query.
1187 $result = mysql_query($query_string, $GLOBAL_dbhandle);
1188
1189 if ($result === FALSE)
1190 {
1191 //Unknown query failure. Return FALSE to the caller. No need to free,
1192 //as this is not a result.
1193 $rv = FALSE;
1194 }
1195 else
1196 {
1197 //Figure out how many rows in the result.
1198 $nrows = mysql_num_rows($result);
1199
1200 if ($nrows == 0)
1201 {
1202 //No rows in the result. The query failed to give us a record, but still
1203 //we need to free the result set.
1204
1205 //Free the result.
1206 mysql_free_result($result);
1207
1208 //The caller gets FALSE. No records.
1209 $rv = FALSE;
1210 }
1211 else
1212 {
1213 //We have at least one record. Grab the indices.
1214 //
1215 for ($i=0; $i<$nrows; $i++)
1216 {
1217 $temp = mysql_fetch_assoc($result);
1218 $rv[$i] = $temp["idx"];
1219 }
1220
1221 //Free the result.
1222 mysql_free_result($result);
1223 }
1224
1225 //Return the value to the caller.
1226 return($rv);
1227 }
1228 }
1229 //
1230 //--------------------------------------------------------------------------------------------------------------
1231
1232 //--------------------------------------------------------------------------------------------------------------
1233 //End of $RCSfile: usrsx.inc,v $.
1234 //--------------------------------------------------------------------------------------------------------------
1235 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25