]> andersk Git - splint.git/blame - test/tests2.4/timecard.c
Pushed back constraintResolve.c to the previous version.
[splint.git] / test / tests2.4 / timecard.c
CommitLineData
80ee600a 1/***************************************************************************
2 Timeclock
3 A small program to collect timecard information
4 -------------------
5 begin : Tue Feb 22 09:41:09 CST 2000
6 copyright : (C) 2000 by Stephen Toothman
7 email : stephen.toothman@cicplan.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19/***************************************************************************
20 * *
21 * This is a complete GPL time clock system for small business. It will *
22 * have a time clock, a reporting system, an user management system, and *
23 * an administrative system for setting system options. The timeclock *
24 * section will rely on several external files when it is finished. *
25 * These files will be an administration file that holds the basic *
26 * company information, such as when the pay week begins and when the *
27 * pay week ends and in future versions may allow different payroll *
28 * systems such as bi-monthly and monthly. The second file will hold a *
29 * list of user ids and a flag for the privileges allowed individual *
30 * user. The last file will be the timecard file that holds the *
31 * individual timecard records. *
32 * *
33 ***************************************************************************/
34
35#ifdef HAVE_CONFIG_H
36#include <config.h>
37#endif
38
39#include <stdio.h>
40#include <stdlib.h>
41#include <time.h>
42#include <ctype.h>
43#include <string.h>
44#include "timecard.h"
45
46
47
48int main(int argc, char *argv[])
49{
50 int i, j;
51 char userid[4] = "zzz"; /* the user id or employee number */
52 int usertype = 0; /* the user type used to determine access */
53 int weekends = 0;
54
55 i = initializeprogram(&userid[0], &usertype, &weekends);
56 j = startprogram(&userid[0], &usertype, &weekends);
57 return EXIT_SUCCESS;
58}
59
60int initializeprogram(char *puserid1, int *pusertype1, int *pweekends1)
61{
62 int m, n, loop;
63 char tempuser[4];
64 int tempusertype, tempweekends;
65
66 m = getenvironment(&tempweekends);
67 n = getuserid(&tempuser[0], &tempusertype);
68 for( loop = 0; loop < 4; loop++)
69 {
70 *puserid1 = toupper((unsigned char) tempuser[loop]);
71 puserid1 = puserid1 + 1;
72 }
73 *pusertype1 = tempusertype;
74 *pweekends1 = tempweekends;
75 return n;
76}
77
78int getenvironment(int *pweekends2)
79{
80 FILE *fp;
81 char fieldname[80];
82 int testvalue;
83 fp = fopen("admin.txt", "r");
84 while ( !feof(fp))
85 {
86 fscanf(fp, "%s %02d\n", fieldname, &testvalue);
87 if (strcmp(fieldname, "WEEKENDS") == 0)
88 {
89 *pweekends2 = testvalue;
90 }
91 }
92 fclose(fp);
93 return 0;
94}
95int getuserid(char *puserid2, int *pusertype2)
96{
97 char *z;
98 char name[80];
99 int w = 0, x = 0, y, loop;
100 FILE *fp;
101 char testuserid[4];
102 int testrights;
103
104 while (x == 0)
105 {
106 printf("Enter your user id\n");
107 z = fgets(name, 80, stdin);
108 y = (z == NULL ? 0 : 1);
109 for( loop = 0; loop < 4; loop++)
110 {
111 if (loop == 3 )
112 {
113 *puserid2 = '\0';
114 }
115 else
116 {
117 *puserid2 = toupper((unsigned char) name[loop]);
118 puserid2 = puserid2 + 1;
119 }
120 }
121 puserid2 = puserid2 - loop + 1;
122 fp = fopen("userlist.txt", "r");
123 while ( !feof(fp) && x == 0)
124 {
125 fscanf(fp, "%s %02d\n", testuserid, &testrights);
126 if (strcmp(puserid2, testuserid) == 0)
127 {
128 x = 1;
129 *pusertype2 = testrights;
130 }
131 }
132 fclose(fp);
133 if ( x == 0 && w >= 1)
134 {
135 printf("You have entered an incorrect user id\n");
136 printf("Please contact your supervisor for assistance.\n");
137 printf("Press <ENTER> to exit\n") ;
138 getchar();
139 exit(1);
140 }
141 if (x == 0 && w < 1)
142 {
143 printf("You have entered an incorrect user id\n");
144 printf("Please enter your information again.\n");
145 w += 1;
146 }
147 }
148 return y;
149}
150
151int startprogram(char *puserid, int *pusertype, int *pweekends)
152{
153 int m, n;
154 char y[80];
155 printf("Please enter what action you wish to take %s -- %d -- %d\n", puserid, *pusertype, *pweekends);
156 while (m < 1 || m > 4)
157 {
158 switch (*pusertype)
159 {
160 case 1 :
161 printf(" 1 Use Timeclock.\n");
162 break;
163 case 2 :
164 printf(" 1 Use Timeclock.\n");
165 printf(" 2 Use Manager functions.\n");
166 break;
167 case 3 :
168 printf(" 1 Use Timeclock.\n");
169 printf(" 2 Use Manager functions.\n");
170 printf(" 3 Use Reporting functions.\n");
171 break;
172 case 4 :
173 printf(" 1 Use Timeclock.\n");
174 printf(" 2 Use Manager functions.\n");
175 printf(" 3 Use Reporting functions.\n");
176 printf(" 4 Use Administrative functions.\n");
177 break;
178 default :
179 printf(" 1 Use Timeclock.\n");
180 break;
181 }
182 printf("\nEnter an item from the list ===> ");
183 fgets(y, 80, stdin);
184 m = atoi(y);
185 /* this if statement checks that an item on the menu was entered */
186 if (m < 1 || m > 4)
187 {
188 printf("\n");
189 printf("The number you entered is not valid.\n");
190 printf("\n");
191 printf("\n");
192 printf("the number must be from the list below. \n");
193
194 m = 0;
195 }
196 if ( m != 0)
197 {
198 switch (*pusertype)
199 {
200 case 1 :
201 if (m != 1)
202 {
203 m = 99;
204 }
205 break;
206 case 2 :
207 if (m != 1 && m != 2)
208 {
209 m = 99;
210 }
211 break;
212 case 3 :
213 if (m != 1 && m != 2 && m != 3)
214 {
215 m = 99;
216 }
217 break;
218 case 4 :
219 if (m != 1 && m != 2 && m != 3 && m != 4)
220 {
221 m = 99;
222 }
223 break;
224 default :
225 if (m != 1)
226 {
227 m = 99;
228 }
229 break;
230 }
231 }
232 if ( m == 99 )
233 {
234 printf("\n");
235 printf("The number you entered is not valid.\n");
236 printf("That number is not an allowed choice.\n");
237 printf("\n");
238 printf("The number must be from the list below. \n");
239
240 m = 0;
241 }
242 }
243 switch (m)
244 {
245 case 1 :
246 {
247 n = timecard(puserid, *pusertype, *pweekends);
248 break;
249 }
250 case 2 :
251 {
252 n = manager(puserid, *pusertype, *pweekends);
253 break;
254 }
255 case 3 :
256 {
257 n = reporter(puserid, *pusertype, *pweekends);
258 break;
259 }
260 case 4 :
261 {
262 n = administrator(puserid, *pusertype, *pweekends);
263 break;
264 }
265 default :
266 {
267 n = timecard(puserid, *pusertype, *pweekends);
268 break;
269 }
270 }
271 return 0;
272}
273
274int timecard(char userid[4], int usertype, int weekends)
275{
276 int j, k, l, n, o, p, loop; /* return and miscellaneous variables */
277
278 timecardrecord currentpunch;
279
280 int itemflag[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} ; /* A flag array to hold whether a time card item has been used */
281 timecardrecord clockpunch[14]; /* an array of structures to hold previous time clock entries */
282
283 char weekstring[3]; /* filename portions */
284 char yearstring[5];
285 char filename[13];
286
287
288 /* The process works as follows: *
289 * First the user id is obtained from the user *
290 * Next the program gets the current time and gets the filename components *
291 * Next the program generates a filename *
292 * Next the program gets an action, clock in or clock out, from the user *
293 * Finally the timecard record is outputed to a file */
294
295 for( loop = 0; loop < 4; loop++)
296 {
297 currentpunch.userid[loop] = userid[loop];
298 }
299 j = gettimeanddate(&currentpunch, &weekstring[0], &yearstring[0], weekends);
300 k = getfilename(&filename[0], &weekstring[0], &yearstring[0]);
301 o = gettimecarddata(&currentpunch, &clockpunch[0], &itemflag[0], &filename[0]);
302 p = printtimecarddata(&currentpunch, &clockpunch[0]);
303 l = getaction(&currentpunch, &clockpunch[0], &itemflag[0]);
304 n = writerecord(&currentpunch, &filename[0]);
305 return n;
306}
307
308int gettimeanddate(timecardrecord *currentpunch, char *pweekstring, char *pyearstring, int weekends)
309{
310 time_t now, test;
311 struct tm *timenow, *timetest, *timetemp;
312
313 int z, adjustfactor;
314 int weekdaynow;
315 int yeartest;
316 char weekstringnow[3], weekstringtest[3];
317 char yearstringnow[5], yearstringtest[5];
318
319 /* get the current time information */
320 now = time(0);
321 timenow = localtime(&now);
322 /* assigns the time information */
323 currentpunch->hour = timenow->tm_hour;
324 currentpunch->minute = timenow->tm_min;
325 currentpunch->second = timenow->tm_sec;
326 currentpunch->day = timenow->tm_mday;
327 currentpunch->month = timenow->tm_mon + 1;
328 currentpunch->year = timenow->tm_year + 1900;
329 weekdaynow = timenow->tm_wday;
330 strftime(weekstringnow, 3, "%U", timenow);
331 strftime(yearstringnow, 5, "%Y", timenow);
332
333 /* Find the adjustment needed to be added to the current time
334 * to return the last day of the pay period */
335 adjustfactor = ((weekends <= weekdaynow) ? 6 - weekdaynow + weekends : weekends - weekdaynow - 1);
336
337 /* get the time information of the last day of the payperiod */
338 timetemp = timenow;
339 timetemp->tm_mday = timetemp->tm_mday + adjustfactor;
340 test = mktime(timetemp);
341 timetest = localtime(&test);
342 yeartest = timetest->tm_year + 1900;
343 strftime(weekstringtest, 3, "%U", timetest);
344 strftime(yearstringtest, 5, "%Y", timetest);
345
346 /* puts the correct information into the file name components */
347 strcpy(pweekstring, weekstringtest);
348 if (currentpunch->year == yeartest)
349 {
350 strcpy(pyearstring, yearstringnow);
351 }
352 else
353 {
354 strcpy(pyearstring, yearstringtest);
355 }
356
357 z = 1;
358 return z;
359}
360
361int getfilename(char *pfilename, char *pweekstring, char *pyearstring)
362{
363 int z;
364
365 /* this code generates the complete file name */
366 sprintf (pfilename, "tc%s%s.tcd", pyearstring, pweekstring);
367
368 z = 1;
369 return z;
370}
371
372int gettimecarddata(timecardrecord *currentpunch, timecardrecord *clockpunch, int *pitemflag, char *pfilename)
373{
374 int a, b, c, d, w = 0, z, y;
375 FILE *fp;
376 char testuserid[4];
377 int testaction, testyear, testmonth, testday, testhour, testminute, testsecond;
378 y = 1;
379 while (w < 14)
380 {
381 strcpy(clockpunch[w].userid, " ");
382 clockpunch[w].action = 0;
383 clockpunch[w].month = 0;
384 clockpunch[w].day = 0;
385 clockpunch[w].year = 0;
386 clockpunch[w].hour = 0;
387 clockpunch[w].minute = 0;
388 clockpunch[w].second = 0;
389 w += 1;
390 }
391
392 if ((fp = fopen(pfilename, "r")) != NULL)
393 {
394 while ( !feof(fp))
395 {
396 fscanf(fp, "%s %02d%02d%02d%04d%02d%02d%02d\n", testuserid, &testaction, &testmonth, &testday, &testyear, &testhour, &testminute, &testsecond);
397 a = strcmp(currentpunch->userid, testuserid);
398 b = (currentpunch->month == testmonth ? 0 : 1);
399 c = (currentpunch->day == testday ? 0 : 1);
400 d = (currentpunch->year == testyear ? 0 : 1);
401 y = ((a == 0 && b == 0 && c == 0 && d == 0) ? 0 : 1);
402 if (y == 0)
403 {
404 z = testaction - 1;
405 strcpy(clockpunch[z].userid, testuserid);
406 clockpunch[z].action = testaction;
407 clockpunch[z].month = testmonth;
408 clockpunch[z].day = testday;
409 clockpunch[z].year = testyear;
410 clockpunch[z].hour = testhour;
411 clockpunch[z].minute = testminute;
412 clockpunch[z].second = testsecond;
413 pitemflag[z] = 1;
414 }
415 }
416 fclose(fp);
417 }
418 return 0;
419}
420
421int printtimecarddata(timecardrecord *currentpunch, timecardrecord *clockpunch)
422{
423 int y = 0, z;
424
425 clearscreen();
426 printf("\n\n%s- -%02d-%02d-%04d-%02d-%02d-%02d\n\n", currentpunch->userid, currentpunch->month, currentpunch->day, currentpunch->year, currentpunch->hour, currentpunch->minute, currentpunch->second);
427
428 while (y < 14)
429 {
430 z = strcmp(clockpunch[y].userid, currentpunch->userid);
431 if (0 == z)
432 {
433 printf("%s-%02d-%02d-%02d-%04d-%02d-%02d-%02d\n", clockpunch[y].userid, clockpunch[y].action, clockpunch[y].month, clockpunch[y].day, clockpunch[y].year, clockpunch[y].hour, clockpunch[y].minute, clockpunch[y].second);
434 }
435 y += 1;
436 }
437 printf("\n");
438 return 0;
439}
440
441int getaction(timecardrecord *currentpunch, timecardrecord *clockpunch, int *pitemflag)
442{
443 int u, v = 0, w = 0, x = 0, z;
444 int i = 0;
445 char y[80];
446 /* This is the action menu */
447 if (pitemflag[0] == 1)
448 {
449 while (w < 14)
450 {
451 u = (clockpunch[w].hour*10000)+(clockpunch[w].minute*100)+(clockpunch[w].second);
452 if (u >= v)
453 {
454 v = u;
455 x = clockpunch[w].action;
456 }
457 if (clockpunch[w].action == 6)
458 {
459 w = 14;
460 v = 6;
461 }
462 w += 1;
463 }
464 }
465 else
466 {
467 x = 0;
468 }
469 while (i < 1 || i > 14)
470 {
471 printf("Please enter what action you wish to take\n");
472 switch (x)
473 {
474 case 0 :
475 printf(" 1 Clock in for the day.\n");
476 break;
477 case 1 :
478 printf(" 2 Clock out for lunch.\n");
479 printf(" 6 Clock out for the day.\n");
480 printf(" 7 Clock out for first break.\n");
481 break;
482 case 2 :
483 printf(" 3 Clock in from lunch.\n");
484 break;
485 case 3 :
486 printf(" 4 Clock out for dinner.\n");
487 printf(" 6 Clock out for the day.\n");
488 if (pitemflag[6] == 0)
489 {
490 printf(" 7 Clock out for first break.\n");
491 }
492 else if (pitemflag[8] == 0)
493 {
494 printf(" 9 Clock out for second break.\n");
495 }
496 else if (pitemflag[10] == 0)
497 {
498 printf("11 Clock out for third break.\n");
499 }
500 else if (pitemflag[12] == 0)
501 {
502 printf("13 Clock out for fourth break.\n");
503 }
504 break;
505 case 4 :
506 printf(" 5 Clock in from dinner.\n");
507 break;
508 case 5 :
509 printf(" 6 Clock out for the day.\n");
510 if (pitemflag[6] == 0)
511 {
512 printf(" 7 Clock out for first break.\n");
513 }
514 else if (pitemflag[8] == 0)
515 {
516 printf(" 9 Clock out for second break.\n");
517 }
518 else if (pitemflag[10] == 0)
519 {
520 printf("11 Clock out for third break.\n");
521 }
522 else if (pitemflag[12] == 0)
523 {
524 printf("13 Clock out for fourth break.\n");
525 }
526 break;
527 case 6 :
528 printf("\n\nYou have exhausted all of your options for today\n");
529 printf("Please contact your supervisor if you believe\n");
530 printf("you have received this message in error or you\n");
531 printf("are not finished working for today.\n");
532 printf("Press <ENTER> to exit\n") ;
533 getchar();
534 exit(1);
535 break;
536 case 7 :
537 printf(" 8 Clock in from first break.\n");
538 break;
539 case 8 :
540 if (pitemflag[1] == 0)
541 {
542 printf(" 2 Clock out for lunch.\n");
543 }
544 else if (pitemflag[3] == 0)
545 {
546 printf(" 4 Clock out for dinner.\n");
547 }
548 printf(" 6 Clock out for the day.\n");
549 printf(" 9 Clock out for second break.\n");
550 break;
551 case 9 :
552 printf("10 Clock in from second break.\n");
553 break;
554 case 10 :
555 if (pitemflag[1] == 0)
556 {
557 printf(" 2 Clock out for lunch.\n");
558 }
559 else if (pitemflag[3] == 0)
560 {
561 printf(" 4 Clock out for dinner.\n");
562 }
563 printf(" 6 Clock out for the day.\n");
564 printf("11 Clock out for third break.\n");
565 break;
566 case 11 :
567 printf("12 Clock in from third break.\n");
568 break;
569 case 12 :
570 if (pitemflag[1] == 0)
571 {
572 printf(" 2 Clock out for lunch.\n");
573 }
574 else if (pitemflag[3] == 0)
575 {
576 printf(" 4 Clock out for dinner.\n");
577 }
578 printf(" 6 Clock out for the day.\n");
579 printf("13 Clock out for fourth break.\n");
580 break;
581 case 13 :
582 printf("14 Clock in from fourth break.\n");
583 break;
584 case 14 :
585 if (pitemflag[1] == 0)
586 {
587 printf(" 2 Clock out for lunch.\n");
588 }
589 else if (pitemflag[3] == 0)
590 {
591 printf(" 4 Clock out for dinner.\n");
592 }
593 printf(" 6 Clock out for the day.\n");
594 break;
595 }
596 printf("\nEnter an item from the list ===> ");
597 fgets(y, 80, stdin);
598 i = atoi(y);
599 /* this if statement checks that an item on the menu was entered */
600 if (i < 1 || i > 14)
601 {
602 printf("\n");
603 printf("The number you entered is not valid.\n");
604 printf("\n");
605 printf("\n");
606 printf("the number must be from the list below. \n");
607
608 i = 0;
609 }
610
611 /* This section of code makes sure that a menu item is only used once */
612 if ( i != 0)
613 {
614 i = (pitemflag[i-1] == 1 ? 98 : i);
615 if ( i == 98 )
616 {
617 printf("\n");
618 printf("The number you entered is not valid.\n");
619 printf("You have already used that action for today\n");
620 printf("\n");
621 printf("the number must be from the list below. \n");
622
623 i = 0;
624 }
625 }
626 if ( i != 0)
627 {
628 switch (x)
629 {
630 case 0 :
631 if (i != 1)
632 {
633 i = 99;
634 }
635 break;
636 case 1 :
637 if (i != 2 && i != 6 && i != 7)
638 {
639 i = 99;
640 }
641 break;
642 case 2 :
643 if (i != 3)
644 {
645 i = 99;
646 }
647 break;
648 case 3 :
649 if (pitemflag[6] == 0)
650 {
651 if (i != 4 && i != 6 && i != 7)
652 {
653 i = 99;
654 }
655 }
656 else if (pitemflag[8] == 0)
657 {
658 if (i != 4 && i != 6 && i != 9)
659 {
660 i = 99;
661 }
662 }
663 else if (pitemflag[10] == 0)
664 {
665 if (i != 4 && i != 6 && i != 11)
666 {
667 i = 99;
668 }
669 }
670 else if (pitemflag[12] == 0)
671 {
672 if (i != 4 && i != 6 && i != 13)
673 {
674 i = 99;
675 }
676 }
677 break;
678 case 4 :
679 if (i != 5)
680 {
681 i = 99;
682 }
683 break;
684 case 5 :
685 if (pitemflag[6] == 0)
686 {
687 if (i != 6 && i != 7)
688 {
689 i = 99;
690 }
691 }
692 else if (pitemflag[8] == 0)
693 {
694 if (i != 6 && i != 9)
695 {
696 i = 99;
697 }
698 }
699 else if (pitemflag[10] == 0)
700 {
701 if (i != 6 && i != 11)
702 {
703 i = 99;
704 }
705 }
706 else if (pitemflag[12] == 0)
707 {
708 if (i != 6 && i != 13)
709 {
710 i = 99;
711 }
712 }
713 break;
714 case 6 :
715 printf("You have exhausted all of your options for today\n");
716 printf("Please contact your supervisor if you believe\n");
717 printf("you have received this message in error or you\n");
718 printf("are not finished working for today.\n");
719 printf("Press <ENTER> to exit\n") ;
720 getchar();
721 exit(1);
722 break;
723 case 7 :
724 if (i != 8)
725 {
726 i = 99;
727 }
728 break;
729 case 8 :
730 if (pitemflag[1] == 0)
731 {
732 if (i != 2 && i != 6 && i != 9)
733 {
734 i = 99;
735 }
736 }
737 else if (pitemflag[3] == 0)
738 {
739 if (i != 4 && i != 6 && i != 9)
740 {
741 i = 99;
742 }
743 }
744 break;
745 case 9 :
746 if (i != 10)
747 {
748 i = 99;
749 }
750 break;
751 case 10 :
752 if (pitemflag[1] == 0)
753 {
754 if (i != 2 && i != 6 && i != 11)
755 {
756 i = 99;
757 }
758 }
759 else if (pitemflag[3] == 0)
760 {
761 if (i != 4 && i != 6 && i != 11)
762 {
763 i = 99;
764 }
765 }
766 break;
767 case 11 :
768 if (i != 12)
769 {
770 i = 99;
771 }
772 break;
773 case 12 :
774 if (pitemflag[1] == 0)
775 {
776 if (i != 2 && i != 6 && i != 13)
777 {
778 i = 99;
779 }
780 }
781 else if (pitemflag[3] == 0)
782 {
783 if (i != 4 && i != 6 && i != 13)
784 {
785 i = 99;
786 }
787 }
788 break;
789 case 13 :
790 if (i != 14)
791 {
792 i = 99;
793 }
794 break;
795 case 14 :
796 if (pitemflag[1] == 0)
797 {
798 if (i != 2 && i != 6)
799 {
800 i = 99;
801 }
802 }
803 else if (pitemflag[3] == 0)
804 {
805 if (i != 4 && i != 6)
806 {
807 i = 99;
808 }
809 }
810 break;
811 }
812 if ( i == 99 )
813 {
814 printf("\n");
815 printf("The number you entered is not valid.\n");
816 printf("That number is not an allowed choice.\n");
817 printf("\n");
818 printf("The number must be from the list below. \n");
819
820 i = 0;
821 }
822 }
823 }
824
825 /* If everything is correct the program assigns the action code to the pointer */
826 currentpunch->action = i;
827
828 z = 1;
829 return z;
830}
831
832int writerecord(timecardrecord *currentpunch, char *pfilename)
833{
834 int a, b, c, d, e, f, g, h, z, y;
835 FILE *fp;
836 char testuserid[4];
837 int testaction, testyear, testmonth, testday, testhour, testminute, testsecond;
838
839 /* opens the file and writes the timecard record to it */
840 fp = fopen(pfilename, "a");
841 fprintf(fp, "%s %02d%02d%02d%04d%02d%02d%02d\n", currentpunch->userid, currentpunch->action, currentpunch->month, currentpunch->day, currentpunch->year, currentpunch->hour, currentpunch->minute, currentpunch->second);
842 fclose(fp);
843
844 /* opens the file and reads back in the record just entered */
845 fp = fopen(pfilename, "r");
846 y = 1;
847 while ( y != 0)
848 {
849 fscanf(fp, "%s %02d%02d%02d%04d%02d%02d%02d\n", testuserid, &testaction, &testmonth, &testday, &testyear, &testhour, &testminute, &testsecond);
850 a = strcmp(currentpunch->userid, testuserid);
851 b = (currentpunch->action == testaction ? 0 : 1);
852 c = (currentpunch->month == testmonth ? 0 : 1);
853 d = (currentpunch->day == testday ? 0 : 1);
854 e = (currentpunch->year == testyear ? 0 : 1);
855 f = (currentpunch->hour == testhour ? 0 : 1);
856 g = (currentpunch->minute == testminute ? 0 : 1);
857 h = (currentpunch->second == testsecond ? 0 : 1);
858 y = a + b + c + d + e + f + g + h;
859 }
860 fclose(fp);
861
862 /* prints both copys of the information for verification */
863 printf("\nprinted to filename %s - %s-%02d-%02d-%02d-%04d-%02d-%02d-%02d\n", pfilename, currentpunch->userid, currentpunch->action, currentpunch->month, currentpunch->day, currentpunch->year, currentpunch->hour, currentpunch->minute, currentpunch->second);
864 printf("read from filename %s - %s-%02d-%02d-%02d-%04d-%02d-%02d-%02d\n", pfilename, testuserid, testaction, testmonth, testday, testyear, testhour, testminute, testsecond);
865 printf("\n\nPress <ENTER> to exit\n") ;
866 getchar();
867
868 z = 1;
869 return z;
870}
871
872int manager(char userid[4], int usertype, int weekends)
873{
874 clearscreen();
875 printf("\n\nManager Functions");
876 printf("\n\nPress <ENTER> to exit\n");
877 getchar();
878 return 0;
879}
880
881int reporter(char userid[4], int usertype, int weekends)
882{
883 char usefile[12];
884 int a, b;
885
886 a = usefilename(&usefile[0]);
887 if (a != 1)
888 {
889 b = printhoursreport(usefile, weekends);
890 }
891 exit(0);
892}
893
894int usefilename(char *pusefile)
895{
896 int h = 0, j;
897 char y[80], z[13];
898 FILE *fp;
899
900 while (h == 0)
901 {
902 printf("Enter the name of the file you wish to open\n");
903 printf("\nThe format for the name is \"tc<year><week number>.tcd\"\n");
904 printf("This means the third week of the year 2000 would be\n");
905 printf("written tc200003.scd.\n");
906 printf("Type \"quit\" to quit the program.\n");
907 printf("Filename : ");
908 fgets(y, 80, stdin);
909 for (j = 0; j < 13; j++)
910 {
911 if (j == 13)
912 {
913 z[j] = '\0';
914 }
915 else
916 {
917 if (y[j] != '\n')
918 {
919 z[j] = y[j];
920 }
921 else
922 {
923 z[j] = '\0';
924 j = 13;
925 }
926 }
927 }
928 if (!strcmp(y , "quit\n"))
929 {
930 printf("quiting\n");
931 return 1;
932 }
933 if ( (fp = fopen(z, "r")) != NULL)
934 {
935 h = 1;
936 fclose(fp);
937 strcpy(pusefile, z);
938 }
939 else
940 {
941 printf("There was an error opening %s. Please try\n", pusefile);
942 printf("entering the file name again\n");
943 h = 0;
944 }
945 }
946 return 0;
947}
948
949int printhoursreport(char usefile[12], int weekends)
950{
951 int e, f;
952 char reportfile[12];
953
954 e = reportfilename(usefile, &reportfile[0]);
955 f = writereportdata(usefile, reportfile, weekends);
956 return 0;
957}
958
959int reportfilename(char usefile[12], char *preportfile)
960{
961 int y;
962 char z[7];
963
964 for (y = 2; y <= 8; y++)
965 {
966 if ( y == 8)
967 {
968 z[y - 2] = '\0';
969 }
970 else
971 {
972 z[y - 2] = usefile[y];
973 }
974 }
975 sprintf (preportfile, "th%s.tcr", z);
976 return 0;
977}
978
979int writereportdata(char usefile[12], char reportfile[12], int weekends)
980{
981 int i,j;
982 daterecord filedates[7];
983
984 i = getreportdates(usefile, &filedates[0], weekends);
985 j = generatereport(usefile, reportfile, filedates);
986 return 0;
987}
988
989int getreportdates(char usefile[12], daterecord *pfiledates, int weekends)
990{
991 time_t now, test;
992 struct tm *timenow, *timetest, *timetemp;
993
994 int a, y, z = 1;
995 int weekfile, weektest;
996 int yearfile;
997 int weekdaynow;
998 char weekstringfile[3], weekstringtest[3];
999 char yearstringfile[5];
1000
1001 /* get the first of year time information */
1002 for (y = 2; y <= 6; y++)
1003 {
1004 if (y == 6)
1005 {
1006 yearstringfile[y - 2] = '\0';
1007 }
1008 else
1009 {
1010 yearstringfile[y - 2] = usefile[y];
1011 }
1012 }
1013 for (y = 6; y <= 8; y++)
1014 {
1015 if (y == 8)
1016 {
1017 weekstringfile[y - 6] = '\0';
1018 }
1019 else
1020 {
1021 weekstringfile[y - 6] = usefile[y];
1022 }
1023 }
1024 weekfile = atoi(weekstringfile);
1025 yearfile = atoi(yearstringfile);
1026 now = time(0);
1027 timenow = localtime(&now);
1028 timetemp = timenow;
1029 timetemp->tm_year = yearfile - 1900;
1030 timetemp->tm_mon = 0;
1031 timetemp->tm_mday = 1;
1032 test = mktime(timetemp);
1033 timetest = localtime(&test);
1034 weekdaynow = timetest->tm_wday;
1035 if (weekdaynow <= weekends)
1036 {
1037 timetemp->tm_mday = timetemp->tm_mday + (6 - weekdaynow + weekends);
1038 test = mktime(timetemp);
1039 timetest = localtime(&test);
1040 timetemp = timetest;
1041 strftime(weekstringtest, 3, "%U", timetest);
1042 weektest = atoi(weekstringtest);
1043 }
1044 else
1045 {
1046 timetemp->tm_mday = timetemp->tm_mday + (weekends - weekdaynow);
1047 test = mktime(timetemp);
1048 timetest = localtime(&test);
1049 timetemp = timetest;
1050 strftime(weekstringtest, 3, "%U", timetest);
1051 weektest = atoi(weekstringtest);
1052 }
1053 while (weektest != weekfile)
1054 {
1055 timetemp->tm_mday = timetemp->tm_mday + 7;
1056 test = mktime(timetemp);
1057 timetest = localtime(&test);
1058 timetemp = timetest;
1059 strftime(weekstringtest, 3, "%U", timetest);
1060 weektest = atoi(weekstringtest);
1061 }
1062 timetemp->tm_mday = timenow->tm_mday - 7;
1063 test = mktime(timetemp);
1064 timetest = localtime(&test);
1065 for (z = 0; z < 7; z++)
1066 {
1067 timetemp->tm_mday = timetemp->tm_mday + 1;
1068 test = mktime(timetemp);
1069 timetest = localtime(&test);
1070 pfiledates[z].day = timetest->tm_mday;
1071 pfiledates[z].month = timetest->tm_mon + 1;
1072 pfiledates[z].year = timetest->tm_year + 1900;
1073 }
1074
1075 return 0;
1076}
1077
1078int generatereport(char usefile[12], char reportfile[12], daterecord filedates[7])
1079{
1080 int a, b, c, d, e, f, y;
1081 FILE *fp, *fq, *fr;
1082 char testuserid1[4], testuserid2[4];
1083 int testaction, testyear, testmonth, testday, testhour, testminute, testsecond, testrights;
1084 float worktime, breaktime;
1085 float reporttimes[14] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} ; /* A flag array to hold whether a time card item has been used */
1086 timecardrecord reportpunch[14]; /* an array of structures to hold previous time clock entries */
1087
1088 fp = fopen("userlist.txt", "r");
1089 fr = fopen(reportfile, "w");
1090 while (!feof(fp))
1091 {
1092 fscanf(fp, "%s %02d\n", testuserid1, &testrights);
1093 fprintf(fr, "%s\n", testuserid1);
1094 fprintf(fr, "Date of Work Work Hours Break Hours\n");
1095 for (a = 0; a < 7; a++)
1096 {
1097 for (b = 0; b < 14; b++)
1098 {
1099 strcpy(reportpunch[b].userid, " ");
1100 reportpunch[b].action = 0;
1101 reportpunch[b].month = 0;
1102 reportpunch[b].day = 0;
1103 reportpunch[b].year = 0;
1104 reportpunch[b].hour = 0;
1105 reportpunch[b].minute = 0;
1106 reportpunch[b].second = 0;
1107 reporttimes[b] = 0.0;
1108 }
1109 if ((fq = fopen(usefile, "r")) != NULL)
1110 {
1111 while ( !feof(fq))
1112 {
1113 fscanf(fq, "%s %02d%02d%02d%04d%02d%02d%02d\n", testuserid2, &testaction, &testmonth, &testday, &testyear, &testhour, &testminute, &testsecond);
1114 e = strcmp(testuserid1, testuserid2);
1115 f = (filedates[a].month == testmonth ? 0 : 1);
1116 c = (filedates[a].day == testday ? 0 : 1);
1117 d = (filedates[a].year == testyear ? 0 : 1);
1118 y = ((e == 0 && f == 0 && c == 0 && d == 0) ? 0 : 1);
1119 if (y == 0)
1120 {
1121 strcpy(reportpunch[testaction].userid, testuserid2);
1122 reportpunch[testaction - 1].action = testaction;
1123 reportpunch[testaction - 1].month = testmonth;
1124 reportpunch[testaction - 1].day = testday;
1125 reportpunch[testaction - 1].year = testyear;
1126 reportpunch[testaction - 1].hour = testhour;
1127 reportpunch[testaction - 1].minute = testminute;
1128 reportpunch[testaction - 1].second = testsecond;
1129 reporttimes[testaction - 1] = (float)(testhour) + (float)(testminute/60.0);
1130 reporttimes[testaction - 1] = (((int)(reporttimes[testaction - 1]*100) % 1 >= 5) ? (((reporttimes[testaction - 1]*100)+ 1)/100.0) : (((reporttimes[testaction - 1]*100)+ 0)/100.0));
1131 }
1132 }
1133 fclose(fq);
1134 breaktime = (reporttimes[7]-reporttimes[6]) + (reporttimes[9]-reporttimes[8]) + (reporttimes[11]-reporttimes[10]) + (reporttimes[13]-reporttimes[12]);
1135 worktime = (reporttimes[5]-reporttimes[0]) - (reporttimes[2]-reporttimes[1]) - (reporttimes[4]-reporttimes[3]);
1136 fprintf(fr, " %02d/%02d/%04d %9.2f %10.2f\n", filedates[a].month, filedates[a].day, filedates[a].year, worktime, breaktime);
1137 }
1138 }
1139 }
1140 fclose(fr);
1141 fclose(fp);
1142 return 0;
1143}
1144
1145int administrator(char userid[4], int usertype, int weekends)
1146{
1147 clearscreen();
1148 printf("\n\nAdministrator Functions");
1149 printf("\n\nPress <ENTER> to exit\n");
1150 getchar();
1151 return 0;
1152}
1153
1154void clearscreen(void)
1155{
1156 int c, d;
1157 for (c = 0; c <= 100; c++)
1158 {
1159 for (d = 0; d <= 200; d++)
1160 {
1161 printf(" ");
1162 }
1163 printf("\n");
1164 }
1165}
This page took 0.210571 seconds and 5 git commands to generate.