Advertisement
Guest User

Untitled

a guest
May 10th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 31.11 KB | None | 0 0
  1. program libray;    // copyright by Wojciech Glapiak
  2.  
  3. uses crt,dos;
  4.  
  5. type
  6.  uzytkownik = record
  7.   imie,nazwisko,haslo,id,data,admin,autoryzacja:string;
  8.  end;
  9.  baza_danych = file of uzytkownik;
  10.  
  11.  ksiazka = record
  12.   imie,nazwisko,tytul,sygnatura,id_user,data_wyp,opis:string;
  13.   max_wyp:integer;
  14.   kara:real;
  15.  end;
  16.  ksiegozbior = file of ksiazka;
  17.  
  18.  
  19. var
  20.  licznik_id:text;
  21.  licznik_syg:text;
  22.  baza:baza_danych;
  23.  ksiazki:ksiegozbior;
  24.  temp:ksiegozbior;
  25.  book:ksiazka;
  26.  user:uzytkownik;
  27.  c,c1,c2:char;
  28.  tablica:array[1..1000] of string;
  29.  y:byte;
  30.  
  31. procedure files;
  32.  begin
  33.   assign(licznik_id,'id.db');
  34.   assign(baza,'baza_danych.db');
  35.   assign(ksiazki,'ksiegozbior.db');
  36.   assign(licznik_syg,'sygnatury.db');
  37.   assign(temp,'temp.db');
  38.  end;
  39.  
  40. function czas:string;
  41.  var
  42.   godz,min,sek,sek100:word;
  43.   sgodz,smin,ssek,time:string;
  44.  begin
  45.   gettime(godz,min,sek,sek100);
  46.   str(godz,sgodz);
  47.   if length(sgodz)=1 then sgodz:='0'+sgodz;
  48.   str(min,smin);
  49.   if length(smin)=1 then smin:='0'+smin;
  50.   str(sek,ssek);
  51.   if length(ssek)=1 then ssek:='0'+ssek;
  52.   time:=' '+sgodz+':'+smin+':'+ssek;
  53.   czas:=time;
  54.  end;
  55.  
  56. function data:string;
  57.  const
  58.   dni:array[0..6] of string=('Niedziela','Poniedzialek','Wtorek','Sroda','Czwartek','Piatek','Sobota');
  59.  var
  60.   rok, miesiac, dzien, dztyg:word;
  61.   sdzien,smiesiac,srok,date:string;
  62.  begin
  63.   getdate(rok, miesiac, dzien, dztyg);
  64.   str(dzien,sdzien);
  65.   if length(sdzien)=1 then sdzien:='0'+sdzien;
  66.   str(miesiac,smiesiac);
  67.   if length(smiesiac)=1 then smiesiac:='0'+smiesiac;
  68.   str(rok,srok);
  69.   date:=dni[dztyg]+' '+sdzien+'.'+smiesiac+'.'+srok;
  70.   data:=date;
  71.  end;
  72.  
  73.  
  74. procedure intro;
  75.  begin
  76.   clrscr;
  77.   writeln(data);
  78.   writeln('godzina',czas);
  79.   writeln;
  80.   writeln('Witam w programie Bibiloteka');
  81.   writeln('Zaloguj się lub zarejestruj');
  82.   gotoxy(59,1);
  83.   writeln('Wcisnij ESC aby wyjsc');
  84.  
  85.  end;
  86.  
  87. function identyfikator:string;
  88.  var
  89.   a,b,id:string;
  90.   c,i,d,kod:integer;
  91.  begin
  92.  clrscr;
  93.   {$I-}
  94.    reset(licznik_id);
  95.    if ioresult <>0 then
  96.     begin
  97.      rewrite(licznik_id);
  98.      writeln(licznik_id,'1');
  99.     end;
  100.   {$I+}
  101.   close(licznik_id);
  102.   reset(licznik_id);
  103.   readln(licznik_id,id);
  104.   a:='cz';
  105.   a:=a+id;
  106.   c:=6-length(a);
  107.   if (c>0) then
  108.    begin
  109.     for i:=1 to c do
  110.      insert('0',a,length(a))
  111.    end;
  112.   val(id,d,kod);
  113.   inc(d);
  114.   str(d,id);
  115.   rewrite(licznik_id);
  116.   write(licznik_id,id);
  117.   close(licznik_id);
  118.   identyfikator:=a;
  119.  end;
  120.  
  121.  
  122. function first_pass(dl:byte):string;
  123.  var
  124.   a:string;
  125.   i:integer;
  126.  begin
  127.   randomize;
  128.   a:='';
  129.   for i:=1 to dl do
  130.    begin
  131.     a:=a+Chr(Ord('a')+Random(26));
  132.    end;
  133.   first_pass:=a;
  134.  end;
  135.  
  136. procedure rejestracja;
  137.  begin
  138.   clrscr;
  139.   {$I-}
  140.    reset(baza);
  141.    if ioresult <>0 then
  142.     begin
  143.      rewrite(baza);
  144.     end;
  145.    close(baza);
  146.   {$I+}
  147.   reset(baza);
  148.   while not eof(baza) do
  149.    begin
  150.     read(baza,user);
  151.    end;
  152.   user.id:=identyfikator;
  153.   writeln('Podaj imie');
  154.   readln(user.imie);
  155.   writeln('Podaj Nazwisko');
  156.   readln(user.nazwisko);
  157.   clrscr;
  158.   writeln('Witaj ',user.imie,'!');
  159.   writeln('Twoje ID sluzace do logowania to: ',user.id);
  160.   user.haslo:=first_pass(6);
  161.   writeln('Twoje haslo tymczasowe to: ',user.haslo);
  162.   user.data:=data;
  163.   writeln;
  164.   user.autoryzacja:='false';
  165.   user.admin:='false';
  166.   write(baza,user);
  167.   writeln('Konto czeka na autoryzacje przez administratora');
  168.   writeln;
  169.   writeln('Gdy administrator autoryzuje Twoje konto bedziesz mogl m.in.:');
  170.   writeln('- wypozyczyc ksiazke');
  171.   writeln('- zarzadzac kontem');
  172.   readln;
  173.  end;
  174.  
  175. function id_k:string;
  176.  var
  177.   a,b,syg:string;
  178.   c,i,d,kod:integer;
  179.  begin
  180.  clrscr;
  181.   {$I-}
  182.    reset(licznik_syg);
  183.    if ioresult <>0 then
  184.     begin
  185.      rewrite(licznik_syg);
  186.      writeln(licznik_syg,'1');
  187.     end;
  188.   {$I+}
  189.   close(licznik_syg);
  190.   reset(licznik_syg);
  191.   readln(licznik_syg,syg);
  192.   a:='K';
  193.   a:=a+syg;
  194.   c:=4-length(a);
  195.   if (c>0) then
  196.    begin
  197.     for i:=1 to c do
  198.      insert('0',a,length(a)-1)
  199.    end;
  200.   val(syg,d,kod);
  201.   inc(d);
  202.   str(d,syg);
  203.   rewrite(licznik_syg);
  204.   write(licznik_syg,syg);
  205.   close(licznik_syg);
  206.   id_k:=a;
  207.  end;
  208.  
  209. procedure zakladanie;
  210.  begin
  211.   clrscr;
  212.   {$I-}
  213.    reset(ksiazki);
  214.    if IOresult<>0 then
  215.     rewrite(ksiazki);
  216.   {$I+}
  217.   close(ksiazki);
  218.   reset(ksiazki);
  219.   while not eof(ksiazki) do
  220.    read(ksiazki,book);
  221.   writeln('Podaj imie autora');
  222.   readln(book.imie);
  223.   writeln('Podaj nazwisko autora');
  224.   readln(book.nazwisko);
  225.   writeln('Podaj tytul ksiazki');
  226.   readln(book.tytul);
  227.   writeln('Podaj krotki opis ksiazki');
  228.   readln(book.opis);
  229.   book.sygnatura:=id_k;
  230.   book.id_user:='';
  231.   book.data_wyp:='';
  232.   writeln('Na ile mozna wypozyczyc ',book.tytul,' ?');
  233.   readln(book.max_wyp);
  234.   write(ksiazki,book);
  235.   clrscr;
  236.   writeln('Dane nowo dodanej ksiazki:');
  237.   writeln('Autor: ',book.imie,' ',book.nazwisko);
  238.   writeln('Tytul: ',book.tytul);
  239.   writeln('Sygnatura: ',book.sygnatura);
  240.   writeln('Opis: ');
  241.   writeln(book.opis);
  242.   writeln('Maksymalna dlugosc wypozyczenia: ',book.max_wyp,'dni');
  243.   readln;
  244.   close(ksiazki);
  245.   clrscr;
  246.   writeln('Czy chcesz dodac nastepna ksiazke?');
  247.   while y<>3 do
  248.   begin
  249.    tablica[1]:='     TAK     ';
  250.    tablica[2]:='     NIE     ';
  251.    textcolor(15);
  252.    for y:=1 to 2 do
  253.     begin
  254.      textcolor(15);
  255.      textbackground(0);
  256.      gotoxy(15,5+y);
  257.      write(tablica[y]);
  258.     end;
  259.    y:=1;
  260.    repeat
  261.     textcolor(0);
  262.     textbackground(15);
  263.     gotoxy(15,5+y);
  264.     write(tablica[y]);
  265.     c1:=readkey;
  266.     c2:=' ';
  267.     if c1=chr(0) then c2:=readkey;
  268.     textcolor(15);
  269.     textbackground(0);
  270.     gotoxy(15,5+y);
  271.     write(tablica[y]);
  272.     if c2='H' then dec(y);
  273.     if c2='P' then inc(y);
  274.     if y=0 then y:=2;
  275.     if y=3 then y:=1;
  276.     if c1=chr(27) then exit;
  277.    until (c1=chr(27)) or (c1=chr(13));
  278.    if y=1 then zakladanie;
  279.    if y=2 then
  280.     begin
  281.      clrscr;
  282.      exit;
  283.     end;
  284.   end;
  285.  end;
  286.  
  287.  
  288.  procedure usuwanie_k;
  289.  var
  290.   counter,i:integer;
  291.  
  292.  begin
  293.   clrscr;
  294.   counter:=0;
  295.   writeln('Wybierz ksiazke do usuniecia');
  296.   {$I-}
  297.    reset(ksiazki);
  298.    if (IOresult <> 0) then
  299.     writeln('Brak ksiegozbioru! Opreracja niemozliwa do wykonania')
  300.    else
  301.     begin
  302.      while not eof(ksiazki) do
  303.       begin
  304.        read(ksiazki,book);
  305.        inc(counter);
  306.        tablica[counter]:=book.tytul;
  307.       end;
  308.      close(ksiazki);
  309.      if tablica[1]='' then
  310.       writeln('Brak ksiazek! Operacja niemozliwa do wykoniania')
  311.      else
  312.      begin
  313.      while (y <> counter+1) do
  314.       begin
  315.        textcolor(15);
  316.        for y:=1 to counter do
  317.        begin
  318.         textcolor(15);
  319.         textbackground(0);
  320.         gotoxy(15,5+y);
  321.         write(tablica[y]);
  322.        end;
  323.        y:=1;
  324.        repeat
  325.         textcolor(0);
  326.         textbackground(15);
  327.         gotoxy(15,5+y);
  328.         write(tablica[y]);
  329.         c1:=readkey;
  330.         c2:=' ';
  331.         if c1=chr(0) then c2:=readkey;
  332.         textcolor(15);
  333.         textbackground(0);
  334.         gotoxy(15,5+y);
  335.         write(tablica[y]);
  336.         if c2='H' then dec(y);
  337.         if c2='P' then inc(y);
  338.         if y=0 then y:=counter;
  339.         if y=(counter+1) then y:=1;
  340.         if c1=chr(27) then exit;
  341.        until (c1=chr(27)) or (c1=chr(13));
  342.        if c1=chr(13) then
  343.         begin
  344.          reset(ksiazki);
  345.          for i:=y to counter-1 do
  346.           begin
  347.            seek(ksiazki,i);
  348.            read(ksiazki,book);
  349.            seek(ksiazki,i-1);
  350.            write(ksiazki,book);
  351.           end;
  352.          seek(ksiazki,counter-1);
  353.          truncate(ksiazki);
  354.          close(ksiazki);
  355.         end;
  356.        writeln('Usunieto!');
  357.        readln;
  358.        clrscr;
  359.        writeln('Czy chcesz usunac nastepna ksiazke?');
  360.        while y<>3 do
  361.        begin
  362.         tablica[1]:='     TAK     ';
  363.         tablica[2]:='     NIE     ';
  364.         textcolor(15);
  365.         for y:=1 to 2 do
  366.        begin
  367.         textcolor(15);
  368.         textbackground(0);
  369.         gotoxy(15,5+y);
  370.         write(tablica[y]);
  371.        end;
  372.        y:=1;
  373.        repeat
  374.         textcolor(0);
  375.         textbackground(15);
  376.         gotoxy(15,5+y);
  377.         write(tablica[y]);
  378.         c1:=readkey;
  379.         c2:=' ';
  380.         if c1=chr(0) then c2:=readkey;
  381.         textcolor(15);
  382.         textbackground(0);
  383.         gotoxy(15,5+y);
  384.         write(tablica[y]);
  385.         if c2='H' then dec(y);
  386.         if c2='P' then inc(y);
  387.         if y=0 then y:=2;
  388.         if y=3 then y:=1;
  389.         if c1=chr(27) then exit;
  390.        until (c1=chr(27)) or (c1=chr(13));
  391.        if y=1 then usuwanie_k;
  392.        if y=2 then
  393.         begin
  394.          clrscr;
  395.          exit;
  396.       end;
  397.      end;
  398.      end;
  399.     end;
  400.    end;
  401.   {$I+}
  402.  end;
  403.  
  404. procedure usuwanie_cz;
  405.  var
  406.   counter,i:integer;
  407.  begin
  408.   clrscr;
  409.   counter:=0;
  410.   i:=0;
  411.   writeln('Wybierz czytelnika do usuniecia');
  412.   {$I-}
  413.    reset(baza);
  414.    if (IOresult <> 0) then
  415.     writeln('Brak bazy danych! Opreracja niemozliwa do wykonania')
  416.    else
  417.     begin
  418.      while not eof(baza) do
  419.       begin
  420.        read(baza,user);
  421.        inc(counter);
  422.        tablica[counter]:=user.id;
  423.       end;
  424.      close(baza);
  425.      if tablica[1]='' then
  426.       writeln('Baza danych pusta! Operacja niemozliwa do wykonania')
  427.      else
  428.      begin
  429.      while (y <> counter+1) do
  430.       begin
  431.        textcolor(15);
  432.        for y:=1 to counter do
  433.        begin
  434.         textcolor(15);
  435.         textbackground(0);
  436.         gotoxy(15,5+y);
  437.         write(tablica[y]);
  438.        end;
  439.        y:=1;
  440.        repeat
  441.         textcolor(0);
  442.         textbackground(15);
  443.         gotoxy(15,5+y);
  444.         write(tablica[y]);
  445.         c1:=readkey;
  446.         c2:=' ';
  447.         if c1=chr(0) then c2:=readkey;
  448.         textcolor(15);
  449.         textbackground(0);
  450.         gotoxy(15,5+y);
  451.         write(tablica[y]);
  452.         if c2='H' then dec(y);
  453.         if c2='P' then inc(y);
  454.         if y=0 then y:=counter;
  455.         if y=(counter+1) then y:=1;
  456.         if c1=chr(27) then exit;
  457.        until (c1=chr(27)) or (c1=chr(13));
  458.        if c1=chr(13) then
  459.         begin
  460.          reset(baza);
  461.          for i:=y to counter-1 do
  462.           begin
  463.            seek(baza,i);
  464.            read(baza,user);
  465.            seek(baza,i-1);
  466.            write(baza,user);
  467.           end;
  468.          seek(baza,counter-1);
  469.          truncate(baza);
  470.          close(baza);
  471.         end;
  472.        writeln('Usunieto!');
  473.        readln;
  474.        clrscr;
  475.        writeln('Czy chcesz usunac nastepnego uzytkownika?');
  476.        while y<>3 do
  477.        begin
  478.         tablica[1]:='     TAK     ';
  479.         tablica[2]:='     NIE     ';
  480.         textcolor(15);
  481.         for y:=1 to 2 do
  482.        begin
  483.         textcolor(15);
  484.         textbackground(0);
  485.         gotoxy(15,5+y);
  486.         write(tablica[y]);
  487.        end;
  488.        y:=1;
  489.        repeat
  490.         textcolor(0);
  491.         textbackground(15);
  492.         gotoxy(15,5+y);
  493.         write(tablica[y]);
  494.         c1:=readkey;
  495.         c2:=' ';
  496.         if c1=chr(0) then c2:=readkey;
  497.         textcolor(15);
  498.         textbackground(0);
  499.         gotoxy(15,5+y);
  500.         write(tablica[y]);
  501.         if c2='H' then dec(y);
  502.         if c2='P' then inc(y);
  503.         if y=0 then y:=2;
  504.         if y=3 then y:=1;
  505.         if c1=chr(27) then exit;
  506.        until (c1=chr(27)) or (c1=chr(13));
  507.        if y=1 then usuwanie_cz;
  508.        if y=2 then
  509.         begin
  510.          clrscr;
  511.          exit;
  512.       end;
  513.      end;
  514.      end;
  515.     end;
  516.    end;
  517.   {$I+}
  518.  end;
  519.  
  520. procedure autoryzacja;
  521.   var
  522.   counter,i,check:integer;
  523.  begin
  524.   clrscr;
  525.   counter:=0;
  526.   writeln('Wybierz czytelnika do autoryzacji');
  527.   {$I-}
  528.    reset(baza);
  529.    if (IOresult <> 0) then
  530.     writeln('Brak bazy danych! Opreracja niemozliwa do wykonania')
  531.    else
  532.     begin
  533.      while not eof(baza) do
  534.       begin
  535.        read(baza,user);
  536.        if user.autoryzacja='false' then
  537.         begin
  538.          inc(counter);
  539.          tablica[counter]:=user.id;
  540.         end;
  541.       end;
  542.      close(baza);
  543.      if tablica[1]='' then
  544.       writeln('Baza danych pusta! Operacja niemozliwa do wykoniania')
  545.      else
  546.      begin
  547.      while (y <> counter+1) do
  548.       begin
  549.        textcolor(15);
  550.        for y:=1 to counter do
  551.        begin
  552.         textcolor(15);
  553.         textbackground(0);
  554.         gotoxy(15,5+y);
  555.         write(tablica[y]);
  556.        end;
  557.        y:=1;
  558.        repeat
  559.         textcolor(0);
  560.         textbackground(15);
  561.         gotoxy(15,5+y);
  562.         write(tablica[y]);
  563.         c1:=readkey;
  564.         c2:=' ';
  565.         if c1=chr(0) then c2:=readkey;
  566.         textcolor(15);
  567.         textbackground(0);
  568.         gotoxy(15,5+y);
  569.         write(tablica[y]);
  570.         if c2='H' then dec(y);
  571.         if c2='P' then inc(y);
  572.         if y=0 then y:=counter;
  573.         if y=(counter+1) then y:=1;
  574.         if c1=chr(27) then exit;
  575.        until (c1=chr(27)) or (c1=chr(13));
  576.        if c1=chr(13) then
  577.         begin
  578.          {$I-}
  579.           reset(baza);
  580.           if IOresult<>0 then
  581.            writeln('Brak bazy danych, zmiana nie mozliwa')
  582.           else
  583.            begin
  584.             repeat
  585.              read(baza,user);
  586.              if (user.id=tablica[y]) then
  587.               begin
  588.                inc(check);
  589.                user.autoryzacja:='true';
  590.               end;
  591.             until (check<>0) or eof(baza);
  592.             if check=0 then
  593.              writeln('Blad')
  594.             else
  595.              begin
  596.               clrscr;
  597.               writeln('Autoryzowano!');
  598.              end;
  599.            end;
  600.           write(baza,user);
  601.           close(baza);
  602.          {$I+}
  603.         end;
  604.        readln;
  605.        clrscr;
  606.        writeln('Czy chcesz autoryzowac konto nastepnego uzytkownika?');
  607.        while y<>3 do
  608.        begin
  609.         tablica[1]:='     TAK     ';
  610.         tablica[2]:='     NIE     ';
  611.         textcolor(15);
  612.         for y:=1 to 2 do
  613.        begin
  614.         textcolor(15);
  615.         textbackground(0);
  616.         gotoxy(15,5+y);
  617.         write(tablica[y]);
  618.        end;
  619.        y:=1;
  620.        repeat
  621.         textcolor(0);
  622.         textbackground(15);
  623.         gotoxy(15,5+y);
  624.         write(tablica[y]);
  625.         c1:=readkey;
  626.         c2:=' ';
  627.         if c1=chr(0) then c2:=readkey;
  628.         textcolor(15);
  629.         textbackground(0);
  630.         gotoxy(15,5+y);
  631.         write(tablica[y]);
  632.         if c2='H' then dec(y);
  633.         if c2='P' then inc(y);
  634.         if y=0 then y:=2;
  635.         if y=3 then y:=1;
  636.         if c1=chr(27) then exit;
  637.        until (c1=chr(27)) or (c1=chr(13));
  638.        if y=1 then autoryzacja;
  639.        if y=2 then
  640.         begin
  641.          clrscr;
  642.          exit;
  643.       end;
  644.      end;
  645.      end;
  646.     end;
  647.    end;
  648.   {$I+}
  649.  end;
  650.  
  651.  
  652.  
  653. procedure lista_cz;
  654.  begin
  655.   {$i-}
  656.    clrscr;
  657.    reset(baza);
  658.    if IOresult<>0 then
  659.     writeln('Barak pliku')
  660.    else
  661.     begin
  662.      while not eof(baza) do
  663.       begin
  664.        read(baza,user);
  665.        writeln(user.imie,' ',user.nazwisko,' ',user.id,' ',user.data,' ',user.autoryzacja);
  666.       end;
  667.     end;
  668.    close(baza);
  669.   {$I+}
  670.   readln;
  671.  end;
  672.  
  673.  
  674. procedure baza_cz;
  675.  begin
  676.   while y<>4 do
  677.    begin
  678.     clrscr;
  679.     tablica[1]:='     Autoryzacja     ';
  680.     tablica[2]:='       Lista         ';
  681.     tablica[3]:='      Usuwanie       ';
  682.     textcolor(15);
  683.     for y:=1 to 3 do
  684.      begin
  685.       textcolor(15);
  686.       textbackground(0);
  687.       gotoxy(15,5+y);
  688.       write(tablica[y]);
  689.      end;
  690.     y:=1;
  691.     repeat
  692.      textcolor(0);
  693.      textbackground(15);
  694.      gotoxy(15,5+y);
  695.      write(tablica[y]);
  696.      c1:=readkey;
  697.      c2:=' ';
  698.      if c1=chr(0) then c2:=readkey;
  699.      textcolor(15);
  700.      textbackground(0);
  701.      gotoxy(15,5+y);
  702.      write(tablica[y]);
  703.      if c2='H' then dec(y);
  704.      if c2='P' then inc(y);
  705.      if y=0 then y:=3;
  706.      if y=4 then y:=1;
  707.      if c1=chr(27) then exit;
  708.     until (c1=chr(27)) or (c1=chr(13));
  709.     if y=1 then autoryzacja;
  710.     if y=2 then lista_cz;
  711.     if y=3 then usuwanie_cz;
  712.    end;
  713.  end;
  714.  
  715. procedure karanie;
  716.  const
  717.   dniowka=1.5;
  718.  var
  719.   dzien,dzien_ob,miesiac,miesiac_ob,rok,rok_ob,k,z,d,roznica_d,roznica_m,roznica_r:integer;
  720.   x:string;
  721.  begin
  722.   while not eof(ksiazki) do
  723.   begin
  724.    d:=0;
  725.    z:=0;
  726.    x:='';
  727.    d:=length(book.data_wyp);
  728.    x:=book.data_wyp;
  729.    z:=pos(' ',x);
  730.    x:=copy(x,z+1,d);
  731.    d:=length(x);
  732.    z:=pos(' ',x);
  733.    val(copy(x,1,z-1),dzien,k);;
  734.    x:=copy(x,z+1,d);
  735.    d:=length(x);
  736.    z:=pos(' ',x);
  737.    val(copy(x,1,z-1),miesiac,k);
  738.    x:=copy(x,z+1,d);
  739.    val(x,rok,k);
  740.    d:=length(data);
  741.    x:=data;
  742.    z:=pos(' ',x);
  743.    x:=copy(x,z+1,d);
  744.    d:=length(x);
  745.    z:=pos(' ',x);
  746.    val(copy(x,1,z-1),dzien_ob,k);;
  747.    x:=copy(x,z+1,d);
  748.    d:=length(x);
  749.    z:=pos(' ',x);
  750.    val(copy(x,1,z-1),miesiac_ob,k);
  751.    x:=copy(x,z+1,d);
  752.    val(x,rok_ob,k);
  753.  
  754.    roznica_d:=(((rok_ob-rok)*12+miesiac_ob-miesiac)*30)+dzien_ob-dzien;
  755.    if roznica_d >=365 then
  756.     begin
  757.      {$I-}
  758.       reset(baza);
  759.       if IOresult <> 0 then writeln('Brak uzytkownikow')
  760.       else
  761.        begin
  762.         while not eof(baza) do
  763.          begin
  764.           read(baza,user);
  765.           if user.id=book.id_user then
  766.           user.autoryzacja:='false';
  767.           writeln(user.id,' ma zablokowane konto z powodu trzymania ksiazki dluzej niz rok');
  768.          end;
  769.        end;
  770.       close(baza);
  771.      {$I+}
  772.     end
  773.    else
  774.     begin
  775.      {$I-}
  776.       reset(baza);
  777.       if IOresult <> 0 then writeln('Brak uzytkownikow')
  778.       else
  779.        begin
  780.         while not eof(baza) do
  781.          begin
  782.           read(baza,user);
  783.           if user.id=book.id_user then
  784.            begin
  785.             book.kara:=roznica_d*dniowka;
  786.             writeln(user.id,' ','przetrzymuje ',book.tytul,' ',roznica_d,'dni');
  787.             writeln('kara: ',book.kara);
  788.            end;
  789.          end;
  790.        end;
  791.       close(baza);
  792.      {$I+}
  793.     end;
  794.    end;
  795.  end;
  796.  
  797.  
  798. procedure stan;
  799.  var
  800.   counter,oddane:integer;
  801.  begin
  802.   clrscr;
  803.   counter:=0;
  804.   write('Ilosc czytelnikow: ');
  805.   {$I-}
  806.    reset(baza);
  807.     if IOresult<>0 then writeln('0')
  808.     else
  809.      writeln(filesize(baza)-1);
  810.    close(baza);
  811.   {$i+}
  812.   {$I-}
  813.    counter:=0;
  814.    reset(ksiazki);
  815.    write('Ilosci ksiazek w bazie: ');
  816.    if IOresult<>0 then writeln('brak bazy')
  817.    else
  818.     begin
  819.      while not eof(ksiazki) do
  820.       begin
  821.        read(ksiazki,book);
  822.        inc(counter);
  823.       end;
  824.      writeln(counter);
  825.     end;
  826.     close(ksiazki);
  827.   {$I+}
  828.   {$I-}
  829.    write('Ksiazki przetrzymywane przez uzytkownikow: ');
  830.    reset(baza);
  831.    reset(ksiazki);
  832.    if IOresult<>0 then writeln('brak bazy uzytkownikow lub ksiazek')
  833.    else
  834.     karanie;
  835.    close(baza);
  836.    close(ksiazki);
  837.   {$I+}
  838.   readln;
  839.  end;
  840.  
  841. procedure bibliotekarz;
  842.  begin
  843.   clrscr;
  844.   writeln('Witamy w panelu bibliotekarza');
  845.   writeln('Wybierz jedna z ponizszych mozliwosci');
  846.   while y<>5 do
  847.   begin
  848.    clrscr;
  849.    tablica[1]:='     Zakladanie ksiegozbioru    ';
  850.    tablica[2]:=' Usuwanie pozycji ksiegozbioru  ';
  851.    tablica[3]:='         Baza Czytelników       ';
  852.    tablica[4]:='         Stan Biblioteki        ';
  853.    textcolor(15);
  854.    for y:=1 to 4 do
  855.     begin
  856.      textcolor(15);
  857.      textbackground(0);
  858.      gotoxy(23,10+y);
  859.      write(tablica[y]);
  860.     end;
  861.    y:=1;
  862.    repeat
  863.     textcolor(0);
  864.     textbackground(15);
  865.     gotoxy(23,10+y);
  866.     write(tablica[y]);
  867.     c1:=readkey;
  868.     c2:=' ';
  869.     if c1=chr(0) then c2:=readkey;
  870.     textcolor(15);
  871.     textbackground(0);
  872.     gotoxy(23,10+y);
  873.     write(tablica[y]);
  874.     if c2='H' then dec(y);
  875.     if c2='P' then inc(y);
  876.     if y=0 then y:=4;
  877.     if y=5 then y:=1;
  878.     if c1=chr(27) then exit;
  879.    until (c1=chr(27)) or (c1=chr(13));
  880.    if y=1 then zakladanie;
  881.    if y=2 then usuwanie_k;
  882.    if y=3 then baza_cz;
  883.    if y=4 then stan;
  884.    y:=1;
  885.   end;
  886.  end;
  887.  
  888. procedure wypozycz;
  889.  var
  890.   counter,i,uzytek,dlugosc:integer;
  891.  
  892.  begin
  893.   clrscr;
  894.   counter:=0;
  895.   uzytek:=0;
  896.   writeln('Wybierz ksiazke do wypozyczenia');
  897.   {$I-}
  898.    reset(ksiazki);
  899.    if (IOresult <> 0) then
  900.     writeln('Brak ksiegozbioru! Opreracja niemozliwa do wykonania')
  901.    else
  902.     begin
  903.      while not eof(ksiazki) do
  904.       begin
  905.        read(ksiazki,book);
  906.        inc(counter);
  907.        if book.id_user=user.id then
  908.         inc(uzytek);
  909.        tablica[counter]:=book.tytul;
  910.       end;
  911.      close(ksiazki);
  912.      if tablica[1]='' then
  913.       writeln('Brak ksiazek! Operacja niemozliwa do wykoniania')
  914.      else
  915.      begin
  916.      if uzytek >=3 then
  917.       writeln('Masz juz 3 wypozyczone ksiazki, wiecej nie mozesz')
  918.      else
  919.      begin
  920.      while (y <> counter+1) do
  921.       begin
  922.        textcolor(15);
  923.        for y:=1 to counter do
  924.        begin
  925.         textcolor(15);
  926.         textbackground(0);
  927.         gotoxy(15,5+y);
  928.         write(tablica[y]);
  929.        end;
  930.        y:=1;
  931.        repeat
  932.         textcolor(0);
  933.         textbackground(15);
  934.         gotoxy(15,5+y);
  935.         write(tablica[y]);
  936.         c1:=readkey;
  937.         c2:=' ';
  938.         if c1=chr(0) then c2:=readkey;
  939.         textcolor(15);
  940.         textbackground(0);
  941.         gotoxy(15,5+y);
  942.         write(tablica[y]);
  943.         if c2='H' then dec(y);
  944.         if c2='P' then inc(y);
  945.         if y=0 then y:=counter;
  946.         if y=(counter+1) then y:=1;
  947.         if c1=chr(27) then exit;
  948.        until (c1=chr(27)) or (c1=chr(13));
  949.        if c1=chr(13) then
  950.         begin
  951.          reset(ksiazki);
  952.          for i:=y to counter-1 do
  953.           begin
  954.            book.id_user:=user.id;
  955.            book.data_wyp:=data;
  956.            book.kara:=0;
  957.            write(ksiazki,book);
  958.            dlugosc:=book.max_wyp;
  959.           end;
  960.          close(ksiazki);
  961.         end;
  962.        writeln('Wpozyczono!');
  963.        writeln('Mozesz trzmac ta ksiazke przez ',dlugosc,' dni');
  964.        readln;
  965.        clrscr;
  966.        writeln('Czy chcesz wypozyczyc nastepna ksiazke?');
  967.        while y<>3 do
  968.        begin
  969.         tablica[1]:='     TAK     ';
  970.         tablica[2]:='     NIE     ';
  971.         textcolor(15);
  972.         for y:=1 to 2 do
  973.        begin
  974.         textcolor(15);
  975.         textbackground(0);
  976.         gotoxy(15,5+y);
  977.         write(tablica[y]);
  978.        end;
  979.        y:=1;
  980.        repeat
  981.         textcolor(0);
  982.         textbackground(15);
  983.         gotoxy(15,5+y);
  984.         write(tablica[y]);
  985.         c1:=readkey;
  986.         c2:=' ';
  987.         if c1=chr(0) then c2:=readkey;
  988.         textcolor(15);
  989.         textbackground(0);
  990.         gotoxy(15,5+y);
  991.         write(tablica[y]);
  992.         if c2='H' then dec(y);
  993.         if c2='P' then inc(y);
  994.         if y=0 then y:=2;
  995.         if y=3 then y:=1;
  996.         if c1=chr(27) then exit;
  997.        until (c1=chr(27)) or (c1=chr(13));
  998.        if y=1 then wypozycz;
  999.        if y=2 then
  1000.         begin
  1001.          clrscr;
  1002.          exit;
  1003.       end;
  1004.      end;
  1005.      end;
  1006.     end;
  1007.    end;
  1008.   {$I+}
  1009.  end;
  1010.  
  1011.  end;
  1012.  
  1013. procedure oddaj;
  1014.  var
  1015.   counter,i,uzytek,dlugosc:integer;
  1016.  
  1017.  begin
  1018.   clrscr;
  1019.   counter:=0;
  1020.   uzytek:=0;
  1021.   writeln('Wybierz ksiazke do oddania');
  1022.   {$I-}
  1023.    reset(ksiazki);
  1024.    if (IOresult <> 0) then
  1025.     writeln('Brak ksiegozbioru! Opreracja niemozliwa do wykonania')
  1026.    else
  1027.     begin
  1028.      while not eof(ksiazki) do
  1029.       begin
  1030.        read(ksiazki,book);
  1031.        inc(counter);
  1032.        if book.id_user=user.id then
  1033.         tablica[counter]:=book.tytul;
  1034.       end;
  1035.      close(ksiazki);
  1036.      if tablica[1]='' then
  1037.       writeln('Brak ksiazek! Nie masz nic wypozyczonego')
  1038.      else
  1039.      begin
  1040.      while (y <> counter+1) do
  1041.       begin
  1042.        textcolor(15);
  1043.        for y:=1 to counter do
  1044.        begin
  1045.         textcolor(15);
  1046.         textbackground(0);
  1047.         gotoxy(15,5+y);
  1048.         write(tablica[y]);
  1049.        end;
  1050.        y:=1;
  1051.        repeat
  1052.         textcolor(0);
  1053.         textbackground(15);
  1054.         gotoxy(15,5+y);
  1055.         write(tablica[y]);
  1056.         c1:=readkey;
  1057.         c2:=' ';
  1058.         if c1=chr(0) then c2:=readkey;
  1059.         textcolor(15);
  1060.         textbackground(0);
  1061.         gotoxy(15,5+y);
  1062.         write(tablica[y]);
  1063.         if c2='H' then dec(y);
  1064.         if c2='P' then inc(y);
  1065.         if y=0 then y:=counter;
  1066.         if y=(counter+1) then y:=1;
  1067.         if c1=chr(27) then exit;
  1068.        until (c1=chr(27)) or (c1=chr(13));
  1069.        if c1=chr(13) then
  1070.         begin
  1071.          if book.kara = 0 then
  1072.          begin
  1073.          reset(ksiazki);
  1074.          for i:=y to counter-1 do
  1075.           begin
  1076.            book.id_user:='';
  1077.            book.data_wyp:='';
  1078.            book.kara:=0;
  1079.            write(ksiazki,book);
  1080.           end;
  1081.          close(ksiazki);
  1082.          writeln('Oddano');
  1083.          end
  1084.         else
  1085.           writeln('Nie mozesz oddac ksiazki poniewaz masz kare wysokosci ',book.kara,'z&#322; za przetrzymywanie ksiazki');
  1086.        readln;
  1087.        clrscr;
  1088.        writeln('Czy chcesz oddac inna ksiazke?');
  1089.        while y<>3 do
  1090.        begin
  1091.         tablica[1]:='     TAK     ';
  1092.         tablica[2]:='     NIE     ';
  1093.         textcolor(15);
  1094.         for y:=1 to 2 do
  1095.        begin
  1096.         textcolor(15);
  1097.         textbackground(0);
  1098.         gotoxy(15,5+y);
  1099.         write(tablica[y]);
  1100.        end;
  1101.        y:=1;
  1102.        repeat
  1103.         textcolor(0);
  1104.         textbackground(15);
  1105.         gotoxy(15,5+y);
  1106.         write(tablica[y]);
  1107.         c1:=readkey;
  1108.         c2:=' ';
  1109.         if c1=chr(0) then c2:=readkey;
  1110.         textcolor(15);
  1111.         textbackground(0);
  1112.         gotoxy(15,5+y);
  1113.         write(tablica[y]);
  1114.         if c2='H' then dec(y);
  1115.         if c2='P' then inc(y);
  1116.         if y=0 then y:=2;
  1117.         if y=3 then y:=1;
  1118.         if c1=chr(27) then exit;
  1119.        until (c1=chr(27)) or (c1=chr(13));
  1120.        if y=1 then oddaj;
  1121.        if y=2 then
  1122.         begin
  1123.          clrscr;
  1124.          exit;
  1125.       end;
  1126.      end;
  1127.     end;
  1128.    end;
  1129.   {$I+}
  1130.  end;
  1131.  end;
  1132.  end;
  1133.  
  1134. procedure stan_konta;
  1135.  begin
  1136.   writeln('Uzytkownik ',user.imie,' ',user.nazwisko);
  1137.   writeln('Twoje ID: ',user.id);
  1138.   writeln('Konto utworzone w dniu: ',user.data);
  1139.   writeln('Wypozyczone ksiazki:');
  1140.   reset(ksiazki);
  1141.   while not eof(ksiazki) do
  1142.    begin
  1143.     if book.id_user=user.id then
  1144.      begin
  1145.       writeln(' ',book.tytul);
  1146.       writeln(' Autor: ',book.imie,' ',book.nazwisko);
  1147.       writeln(' Data wypozyczenia: ',book.data_wyp);
  1148.       writeln(' Ksiazka zostala wypozyczona na: ',book.max_wyp,' dni');
  1149.       if book.kara<>0 then
  1150.        writeln(' Kara za przetrzymanie wynosi: ',book.kara,' zl');
  1151.      end;
  1152.    end;
  1153.   close(ksiazki);
  1154.   readln;
  1155.  end;
  1156.  
  1157. procedure zmien_haslo;
  1158.  begin
  1159.  end;
  1160.  
  1161. procedure otworz_biblioteke;
  1162.  begin
  1163.  end;
  1164.  
  1165. procedure usun_konto;
  1166.  begin
  1167.  end;
  1168.  
  1169. procedure czytelnik;
  1170.  begin
  1171.   clrscr;
  1172.   if user.autoryzacja='false' then
  1173.    begin
  1174.     writeln('Twoje konto nie jest autoryzowane przez administratora lub zostalo zablokowane');
  1175.     writeln('sproboj pozniej lub skontaktuj sie z administratorem');
  1176.    end
  1177.   else
  1178.    begin
  1179.     writeln('Witamy w panelu czytelnika');
  1180.     writeln('Wybierz jedna z ponizszych mozliwosci');
  1181.     while y<>7 do
  1182.      begin
  1183.       clrscr;
  1184.       tablica[1]:='   Wyporzycz ksiazke  ';
  1185.       tablica[2]:='     Oddaj ksiazke    ';
  1186.       tablica[3]:='      Stan konta      ';
  1187.       tablica[4]:='     Zmien haslo      ';
  1188.       tablica[5]:='     Ksiegozbior      ';
  1189.       tablica[6]:='      USUN Konto      ';
  1190.       textcolor(15);
  1191.       for y:=1 to 6 do
  1192.        begin
  1193.         textcolor(15);
  1194.         textbackground(0);
  1195.         gotoxy(23,10+y);
  1196.         write(tablica[y]);
  1197.        end;
  1198.       y:=1;
  1199.       repeat
  1200.        textcolor(0);
  1201.        textbackground(15);
  1202.        gotoxy(23,10+y);
  1203.        write(tablica[y]);
  1204.        c1:=readkey;
  1205.        c2:=' ';
  1206.        if c1=chr(0) then c2:=readkey;
  1207.        textcolor(15);
  1208.        textbackground(0);
  1209.        gotoxy(23,10+y);
  1210.        write(tablica[y]);
  1211.        if c2='H' then dec(y);
  1212.        if c2='P' then inc(y);
  1213.        if y=0 then y:=6;
  1214.        if y=7 then y:=1;
  1215.        if c1=chr(27) then exit;
  1216.       until (c1=chr(27)) or (c1=chr(13));
  1217.       if y=1 then wypozycz;
  1218.       if y=2 then oddaj;
  1219.       if y=3 then stan_konta;
  1220.       if y=4 then zmien_haslo;
  1221.       if y=5 then otworz_biblioteke;
  1222.       if y=6 then usun_konto;
  1223.      end;
  1224.     end;
  1225.  end;
  1226.  
  1227. procedure logowanie;
  1228.  var
  1229.   login,has:string;
  1230.   check,licznik:byte;
  1231.   c:char;
  1232.  begin
  1233.   has:='';
  1234.   licznik:=0;
  1235.   clrscr;
  1236.   check:=0;
  1237.   write('login: ');
  1238.   readln(login);
  1239.   clrscr;
  1240.   write('haslo: ');
  1241.   while c<>chr(13) do
  1242.    begin
  1243.     c:=readkey;
  1244.     inc(licznik);
  1245.     has[licznik]:=c;
  1246.     has:=has+has[licznik];
  1247.     write('*');
  1248.    end;
  1249.   has:=copy(has,1,length(has)-1);
  1250.   begin
  1251.   {$I-}
  1252.    reset(baza);
  1253.    if IOresult<>0 then
  1254.     begin
  1255.      writeln;
  1256.      writeln;
  1257.      writeln('Brak bazy danych, operacja niemozliwa');
  1258.      writeln('Nastapi cofniecie na strone glowna');
  1259.      delay(3000);
  1260.     end
  1261.    else
  1262.     begin
  1263.      repeat
  1264.       read(baza,user);
  1265.       if (login=user.id) then
  1266.        begin
  1267.         if (has=user.haslo) then
  1268.          begin
  1269.           inc(check);
  1270.           if user.admin='true' then
  1271.            bibliotekarz
  1272.           else
  1273.            czytelnik;
  1274.          end;
  1275.        end;
  1276.      until (check<>0) or eof(baza);
  1277.     if check=0 then
  1278.     writeln('Zle dane lub nie masz zalozonego konta');
  1279.     close(baza);
  1280.     readln;
  1281.    end;
  1282.   {$I+}
  1283.   end;
  1284.  
  1285.  end;
  1286.  
  1287. procedure be_admin;
  1288.  
  1289.  const
  1290.   max=5;
  1291.  
  1292.  var
  1293.   ad,has,access:string;
  1294.   check,i:byte;
  1295.   c:char;
  1296.  begin
  1297.   clrscr;
  1298.   access:='';
  1299.   check:=0;
  1300.   writeln('Podaj haslo: ');
  1301.   for i:=1 to max do
  1302.    begin
  1303.     c:=readkey;
  1304.     write('*');
  1305.     access[i]:=c;
  1306.     access:=access+access[i];
  1307.    end;
  1308.   if (access = 'l0pht') then
  1309.    begin
  1310.     clrscr;
  1311.     writeln('Uwaga ten panel ingeruje gleboko w baze danych, uzywaj go rozwaznie!');
  1312.     writeln('Podaj ID do zmiany konta uzytkownika na konto administratora');
  1313.     readln(ad);
  1314.     writeln('Nowe haslo');
  1315.     readln(has);
  1316.     {$I-}
  1317.      reset(baza);
  1318.      if IOresult<>0 then
  1319.       writeln('Brak bazy danych, zmiana nie mozliwa')
  1320.      else
  1321.       begin
  1322.        repeat
  1323.         read(baza,user);
  1324.         if (user.id=ad) then
  1325.          begin
  1326.           seek(baza,filepos(baza)-1);
  1327.           inc(check);
  1328.           user.haslo:=has;
  1329.           user.id:='bibliotekarz';
  1330.           user.admin:='true';
  1331.           user.autoryzacja:='true';
  1332.          end;
  1333.        until (check<>0) or eof(baza);
  1334.        if check=0 then
  1335.         writeln('Uzytkownik o podanym ID nie istnieje')
  1336.        else
  1337.         begin
  1338.          writeln('Twoje NOWE ID to "bibliotekarz"');
  1339.          writeln('Powodzenia w administrowaniu biblioteka');
  1340.         end;
  1341.        write(baza,user);
  1342.        close(baza);
  1343.        readln;
  1344.       end;
  1345.     {$I+}
  1346.    end
  1347.   else
  1348.    exit;
  1349.  end;
  1350.  
  1351.  
  1352. procedure menu;
  1353.  begin
  1354.   clrscr;
  1355.   intro;
  1356.   writeln;
  1357.   while y<>3 do
  1358.   begin
  1359.    tablica[1]:='        Logowanie          ';
  1360.    tablica[2]:='  Rejestracja w systemie   ';
  1361.    textcolor(15);
  1362.    for y:=1 to 2 do
  1363.     begin
  1364.      textcolor(15);
  1365.      textbackground(0);
  1366.      gotoxy(30,10+y);
  1367.      write(tablica[y]);
  1368.     end;
  1369.    y:=1;
  1370.    repeat
  1371.     textcolor(0);
  1372.     textbackground(15);
  1373.     gotoxy(30,10+y);
  1374.     write(tablica[y]);
  1375.     c1:=readkey;
  1376.     c2:=' ';
  1377.     if c1=chr(0) then c2:=readkey;
  1378.     textcolor(15);
  1379.     textbackground(0);
  1380.     gotoxy(30,10+y);
  1381.     write(tablica[y]);
  1382.     if c2='H' then dec(y);
  1383.     if c2='P' then inc(y);
  1384.     if c2='M' then
  1385.      begin
  1386.       be_admin;
  1387.       clrscr;
  1388.       menu;
  1389.      end;
  1390.     if y=0 then y:=2;
  1391.     if y=3 then y:=1;
  1392.     if c1=chr(27) then exit;
  1393.    until (c1=chr(27)) or (c1=chr(13));
  1394.    if y=1 then logowanie;
  1395.    if y=2 then rejestracja;
  1396.    clrscr;
  1397.    intro;
  1398.   end;
  1399.  end;
  1400.  
  1401. begin
  1402.  clrscr;
  1403.  files;
  1404.  menu;
  1405. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement