]> 4ch.mooo.com Git - bakadb.git/blob - bakadb.c
Merge branch 'master' of ssh://4ch.mooo.com:26/var/www/16/bakadb
[bakadb.git] / bakadb.c
1 /*
2  * Copyright (C) 2015 sparky4
3  *
4  * This file is part of baka database.
5  *
6  * baka database is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * baka database is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 //TODO
23 //price! and finish it
24 //additional paramiters
25 //make and model
26 //simple batch files
27 //color wwww
28 //
29 //for turbo goat!
30 //gui
31 //big font!
32 //customer dtabase
33
34 #include "bakadb.h"
35
36 byte *pc = NULL;
37 byte sheetstr[sizeof(byte)*((80*50)+1)];
38 byte *bakapee = NULL;
39 iword found_id=0;
40
41
42 iword baka_id;              //work order number
43 iword bakacust_id;              //customer id
44 byte bakacust_lastname[64];     //name of client
45 byte bakacust_firstname[64];     //name of client
46 byte bakacust_phone[64];     //phopne number of client
47 byte bakacust_address[64];     //address of client
48 byte bakacust_zipcode[64];     //zipcode
49 byte baka_desc[4096];     //Description of the problem
50 time_t                          baka_date;
51 byte baka_price;                        //price
52 word baka_done;                 //is it done?
53
54 /*
55         "%[^\n]"
56 */
57
58 void bdwr(void)
59 {
60         byte str[BAKAPEE], strc[BAKAPEE], buff[BAKAPEE], st[24];
61         byte *pc = NULL;
62         byte *p;
63
64         FILE *inbaka = fopen ( BAKADB, "r+" );
65         FILE *outbaka = NULL;
66         FILE *incust = fopen ( CUSTDB, "r+" );
67         FILE *outcust = NULL;
68         if(inbaka == NULL)
69         {
70                 newdb:
71                 fclose(inbaka);
72                 outbaka = fopen ( BAKADB, "w+" );
73                 printf("\nNew database being made ^^;\n");
74                 printf("Work order number: ");
75                 scanf("%ud\n", &baka_id);   // input~
76                 if(baka_id==0) baka_id=1;
77         }
78         else
79         {
80                 fgets(buff, 1, inbaka);
81                 if(buff==NULL)
82                 {
83                         unlink(BAKADB);
84                         goto newdb;
85                 }
86                 while ( fgets ( buff, sizeof buff, inbaka) != NULL );
87                 fclose(inbaka);
88                 pc = strtok(buff, SEPE);
89                 baka_id = atoi(pc);
90                 baka_id++;
91                 outbaka = fopen ( BAKADB, "a+" );
92                 outcust = fopen ( CUSTDB, "a+" );
93                 //printf("      baka_id=%u\n", baka_id);
94         }
95         sprintf(st, "%u", baka_id);
96         strcpy(str, st);
97         strcat(str,SEPE);
98
99         strcpy(str, st);
100         strcat(strc,SEPE);
101
102         //input 1st and last~
103         printf("Client's name Last Name: ");
104         scanf("%s", &(bakacust_lastname));     // input~
105         printf("Client's name First Name: ");
106         scanf("%s", &(bakacust_firstname));     // input~
107
108         //TODO make uppercased names
109         found_id=0;
110         cmpstrfromdb(1);        //++++update
111
112         strcat(str,bakacust_lastname);  strcat(str,SEPE);
113         strcat(str,bakacust_lastname);  strcat(str,SEPE);
114         strcat(str,bakacust_lastname);  strcat(str,SEPE);
115         if(found_id==0)
116         {
117                 printf("Client's Phone Number: ");
118                 scanf("%s", &(bakacust_phone));     // input~
119         }else getstrfromdb(2);
120         strcat(str,baka_phone);  strcat(str,SEPE);
121         if(found_id==0)
122         {
123                 printf("Client's Address: ");
124                 scanf("%s", &(baka_address));     // input~
125         }else getstrfromdb(3);
126         strcat(str,baka_address);  strcat(str,SEPE);
127
128         printf("Description of the Problem: ");
129         scanf("%s", &(baka_desc));     // input~
130         strcat(str,baka_desc); strcat(str,SEPE);
131         //time
132         memset(st, 0, sizeof st);       //reset str~
133         baka_date=time(NULL);
134         sprintf(st, "%s", ctime(&baka_date));
135         p = &st;
136         p++; /* 'N' is not in `p` */
137         p[strlen(p)-1] = 0; /* 'P' is not in `p` (and it isn't in `mystr` either) */
138         //printf("[%s]", st);
139         strcat(str, st);        strcat(str,SEPE);
140
141         //price var
142         strcat(str, "0"); strcat(str,SEPE);
143
144         //done var
145         strcat(str,"0");
146         strcat(str,SEPE);
147         strcat(str,"\n");
148         //bdmksheet(&bddb);
149         fwrite(str, strlen(str), 1, outbaka);
150         fclose(outbaka);
151         found_id=0;
152         free(pc);
153 }
154
155 void bddone(iword id)
156 {
157         byte buff[BAKAPEE], st[16], str[BAKAPEE];
158         byte *p;
159         siword eed;
160
161         FILE *in = fopen ( BAKADB, "r" );
162         FILE *out = NULL;
163         while ( fgets ( buff, sizeof buff, in ) != (NULL) )
164         {
165                 strcat(str, buff);
166                 pc = strtok(buff, SEPE);
167                 eed = atoi(pc);
168                 if(eed!=id)
169                 {
170                         continue;
171                 }
172                 else
173                 {
174                         sprintf(st, "%d", "1");
175                         p = &str;
176                         p++; /* 'N' is not in `p` */
177                         p[strlen(p)-4] = st[0]; /* 'P' is not in `p` (and it isn't in `mystr` either) */
178                         //printf("[%d]\n", eed);
179                 }
180         }
181         fclose(in);
182         out = fopen ( BAKADB, "w+" );
183         fwrite(str, strlen(str), 1, out);
184         fclose(out);
185         free(p);
186 }
187
188 void bdchange(iword id, byte i, sword t)
189 {
190         byte buff[BAKAPEE], str[BAKAPEE];
191         //siword st;
192         byte *p;
193         siword eed;
194
195         FILE *in = fopen ( BAKADB, "r" );
196         FILE *out = NULL;
197         dbvar(t);
198         found_id=id;
199         while ( fgets ( buff, sizeof buff, in ) != (NULL) )
200         {
201                 strcat(str, buff);
202                 pc = strtok(buff, SEPE);
203                 eed = atoi(pc);
204                 if(eed!=id)
205                 {
206                         continue;
207                 }
208                 else
209                 {
210                         getstrfromdb(-2);
211                         //sprintf(st, "%f", );
212                         p = &str;
213                         p++; /* 'N' is not in `p` */
214                         p[strlen(p)+(t*4)] = ((*bakapee)+(iword)(i)); /* 'P' is not in `p` (and it isn't in `mystr` either) */
215                         //printf("[%d]\n", eed);
216                 }
217         }
218         fclose(in);
219         out = fopen ( BAKADB, "w+" );
220         fwrite(str, strlen(str), 1, out);
221         fclose(out);
222         free(p);
223 }
224
225 void mksheetdrbd()
226 {
227         byte str[BAKAPEE*16], boo[BAKAPEE], st[24];
228         FILE *out = fopen ( "sheet.txt", "w+" );
229
230 //make sheet
231         strcpy(str, "Dr. Bulldog Computers                                      (318) 255-0333\n");
232         strcat(str, "208 N Trenton Street                                       Monday - Friday\n");
233         strcat(str, "Ruston, LA 71270                                   10:00 AM – 6:00 PM\n");
234         strcat(str, "Personal Information\n");
235         strcat(str,"Name: ");
236 //      getstrfromdb(1);
237 //      strcpy(baka_name, pc); strcat(str, baka_name); strcat(str, "            ");
238 //      strcat(str,"Date: ");
239 //      sprintf(st, "%s", baka_date);
240 //      strcat(str, st); strcat(str, "\n");
241 /*
242 Street Address: _____________________________ City: _______________ State: _____ Zip: _________
243 Phone:  Cell (        ) ______________ other: (        ) ________________ E-mail:______________________
244 Name of person referred you to us, if any: ___________________________________________
245 System Information
246 Brand: ______________Model: ____________Login Password:____________ Serial No:_____________
247 Accessories Included (Charger, External HDD, etc.): ___________________________________________
248 Problem Description (Please be specific)
249 __________________________________________________________________________________________________________________________________________________________________________
250 Data Backup
251 Before any repairs are made, please inform us of any data that you want saved. Programs cannot be backed up and must be reinstalled after a format operation. Anything NOT listed here is permanently deleted. Check all that apply:
252 I DO NOT NEED ANY BACKUPS  *All data will be deleted*
253 I DO NOT ALLOW A FORMAT *The software will not be altered in any way*
254 Personal Data (My Documents, My Pictures, My Music, My Videos, IE Favorites, Desktop)
255 E-Mail (Microsoft Outlook, Outlook Express, or Windows Mail)
256 Other (Be Specific) _______________________________________________________________
257 Legal
258 By signing this form I authorize Dr. Bulldog Computers to perform any necessary actions to repair problem as described above. I also understand that I left a malfunctioning unit that may have other problems in addition to the ones described. We quote for walk-in customers however in the case a device cannot be repaired, a $45 diagnostics fee will be charged and the device will be returned broken. Leaving your device with Dr. Bulldog for hardware repairs voids any warranty with any other company. All provided repair times are an estimate. In the event of data loss, Dr. Bulldog is not responsible for recovering the data in any way. I accept that all software on this device belongs to me and can provide any licensing necessary. The device also belongs to me, is NOT stolen, and has no liens attached.  I also agree that Dr.Bulldog Computer is not responsible for the machine(s) that I left past 30 days after the take-in date and special orders that I make cannot be refunded.
259 Customer Signature: ______________________________   Date: ___/___/___*/
260         fclose(out);
261 }
262
263 void dbvar(sword i)
264 {
265         switch(i)
266         {
267                 case 0:
268                         bakapee = NULL;
269                         bakapee = (byte *)baka_id;
270                 break;
271                 case 1:
272                         bakapee = NULL;
273                         bakapee = &baka_name;
274                 break;
275                 case 2:
276                         bakapee = NULL;
277                         bakapee = &baka_phone;
278                 break;
279                 case 3:
280                         bakapee = NULL;
281                         bakapee = &baka_address;
282                 break;
283                 case -2:
284                         bakapee = NULL;
285                         bakapee = &baka_price;
286                 break;
287                 default:
288                         bakapee = NULL;
289                 break;
290         }
291 }
292
293 void getstrfromdb(sword i)
294 {
295         byte buff[BAKAPEE];
296         word q;
297         FILE *in = fopen ( BAKADB, "r+" );
298         if(found_id>0) dbvar(i);
299         while ( fgets ( buff, sizeof buff, in ) != NULL )
300         {
301                 pc = strtok(buff, SEPE);
302                 if(found_id==atoi(pc))
303                 {
304                         break;
305                 }
306         }
307         if(i>=0)
308         {
309                 for(q=0;(q<i);q++)
310                 {
311                         pc = strtok(NULL, SEPE);
312                 }
313         }
314         else
315         {
316                 for(q=0;(q>i);q--)
317                 {
318                         pc = strtok(SEPE, NULL);
319                 }
320         }
321         if(found_id>0)
322                 strcpy(bakapee, pc);
323         fclose(in);
324 }
325
326 void cmpstrfromdb(word i)
327 {
328         byte buff[BAKAPEE];
329         byte pee[16];
330         word q;
331         FILE *in = fopen ( BAKADB, "r+" );
332         dbvar(i);
333         while ( fgets ( buff, sizeof buff, in ) != NULL )
334         {
335                 pc = strtok(buff, SEPE);
336                 found_id=atoi(pc);
337                 for(q=0;q<i;q++)
338                 {
339                         pc = strtok(NULL, SEPE);
340                 }
341                 if(strcmp(bakapee, pc)<1)
342                 {
343                         strcpy(pc, bakapee);
344                         break;
345                 }else found_id=0;
346         }
347         fclose(in);
348 }