/
request.class.php
1377 lines (1183 loc) · 42.8 KB
/
request.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
//------------------------------------------------------------------------------
// Author: Denise
// Date : November/2003
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
log_msg("entrei no request.class");
//include_once ("tiffFunctions.php");
include_once ("gralhaFunctions.php");
include_once("media.class.php");
include_once("globalsFunctions.php");
//include_once("g2t.class.php");
//include_once("p2u.class.php");
//include_once("p2c.class.php");
//include_once("m2c.class.php");
//include_once("m2d.class.php");
//include_once("d2g.class.php");
//include_once("h2t.class.php");
//include_once("c2h.class.php");
//include_once("drdFunctions.php");
log_msg("terminei import do request.class");
//------------------------------------------------------------------------------
// Class Request
//------------------------------------------------------------------------------
class Request
{
var $reqId;
var $userId;
var $reqDate;
var $statusDate;
var $payDate;
var $delDate;
var $priority;
var $nItens;
var $nItensDone;
var $itens;
var $total;
var $status;
var $operator;
var $addressId;
var $bd;
var $reqIp;
var $reqCountry;
function Request($bd)
{
$this->reqId = "";
$this->userId = "";
$this->reqDate = 0;
$this->statusDate = 0;
$this->payDate = 0;
$this->delDate = 0;
$this->priority = 0;
$this->nItens = 0;
$this->nItensDone = 0;
$this->total = 0;
$this->operator="";
$this->addressId=0;
$this->bd = $bd;
$this->reqIp = "";
$this->reqCountry = "";
}
function fill($parUser, $parDate=0, $parStatusDate=0, $parPayDate=0,
$pardelDate=0, $parPri = 0, $parOperator = "", $parAddress=0, $parIp = "",$parCountry = "")
{
// Filling attributes
$this->userId = $parUser;
if($parDate != 0) $this->reqDate = $parDate;
if($parStatusDate != 0) $this->statusDate = $parStatusDate;
if($parPayDate != 0) $this->payDate = $parPayDate;
if($pardelDate != 0) $this->delDate = $pardelDate;
if($parPri != 0) $this->priority = $parPri;
if(trim($parOperator) != "") $this->operator = $parOperator;
if($parAddress != 0) $this->addressId = $parAddress;
$this->reqIp = $parIp;
$this->reqCountry = $parCountry;
$this->total = 0;
}
function insert()
{
// Make the INSERT query statement
$sql = "INSERT INTO Request ";
$sql .= "(UserId, ReqDate, StatusDate, PayDate, DelDate, ";
$sql .= "Priority, Operator, addressId, Ip, Country) VALUES ('";
$sql .= $this->userId . "', '" . $this->reqDate . "', '";
$sql .= $this->statusDate . "', '" . $this->payDate . "', '" . $this->delDate . "', '";
$sql .= $this->priority . "', '" . $this->operator . "', '" . $this->addressId . "', '";
$sql .= $this->reqIp . "', '" . $this->reqCountry . "')";
// Query
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
$this->reqId = $this->bd->insertId();
return $this->reqId;
}
function modify($parReqId=0)
{
// Verifying Parameter
if(!$parReqId)
$parReqId = $this->reqId;
// Make the UPDATE query statement
$sql = "UPDATE Request SET ";
$sql .= "UserId = '" . $this->userId . "',";
$sql .= "ReqDate = '" . $this->reqDate . "',";
$sql .= "StatusDate = '" . $this->statusDate . "',";
$sql .= "PayDate = '" . $this->payDate . "', ";
$sql .= "DelDate = '" . $this->delDate . "',";
$sql .= "Priority = " . $this->priority;
$sql .= "Operator = '" . $this->operator . "',";
$sql .= "addressId = " . $this->addressId;
$sql .= " WHERE ReqId = " . $parReqId ;
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
else
return true;
}
function removeItem($numItem)
{
for($i=0; $i < $this->nItens; $i++)
if($this->itens[$i]->numItem == $numItem)
{
$auxStatus = $this->itens[$i]->status;
$this->itens[$i]->remove();
}
$this->nItens--;
if( $auxStatus == 'F') $this->nItensDone--;
//$this->modify();
}
function removeParc($parReqId=0)
{
// Remove the current Request
if(!$parReqId) $parReqId = $this->reqId;
$sql = "DELETE FROM Request WHERE ReqId = " . $parReqId ;
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
else
return true;
}
function removeComp($parReqId=0)
{
// Using parameter, you have to fill all itens fields
if($parReqId)
if(!$this->searchComp($parRegId)) return 0;
// Remove the current Request
if(!$parReqId) $parReqId = $this->reqId;
// Remove request itens
for($i = 0; $i < $this->nItens; $i++)
if(!$this->itens[$i]->remove()) return 0;
$sql = "DELETE FROM Request WHERE ReqId = " . $parReqId ;
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
return true;
}
function search($parReqId)
{
$sql = "SELECT * FROM Request WHERE ReqId = $parReqId";
$this->bd->query($sql) or $this->bd->error($sql);
$nReq = $this->bd->numRows();
if(!$nReq)
{
echo "<br>Nenhum pedido encontrado!</br>";
return false;
}
$row_array = $this->bd->fetchRow();
$this->fillAttrib($row_array);
return true;
}
function searchAll(&$nReq, $parUser="", $parDataI="", $parDataE="", $parStat="")
{
// Mounting the SQL
$sql = "SELECT * FROM Request WHERE UserId LIKE '$parUser'";
if(trim($parDataI) != "") $sql .= " and ReqDate > '" . $parDataI . "' and ReqDate < '" . $parDataE . "'";
if(trim($parStat) != "")
{
if($parStat == "open")
$sql .= " and NItem > NItemDone";
else
if($parStat == "closed") $sql .= " and NItem <= NItemDone";
}
// Order
$sql .= " ORDER BY ReqId";
// Query
$this->bd->query($sql) or $this->bd->error($sql);
$nReq = $this->bd->numRows();
if(!$nReq)
{
echo "<br>Nenhum pedido encontrado!</br>";
return false;
}
for($i = 0; $i < $nReq; $i++)
$row_array[$i] = $this->bd->fetchRow($i);
return $row_array;
}
function searchComp($parReqId)
{
// Seacrh the request
if(!$this->search($parReqId))
return false;
// Search all itens for this request
for($i = 0; $i < $this->nItens; $i++)
{
$this->itens[$i] = new RequestItem($this->bd);
$this->itens[$i]->search($i, $parReqId);
$this->total += $this->itens[$i]->price;
}
}
function fillAttrib($row)
{
// Filling attributes from the Data Base
$this->reqId = $row["ReqId"];
$this->userId = $row["UserId"];
$this->reqDate = $row["ReqDate"];
$this->statusDate = $row["StatusDate"];
$this->payDate = $row["PayDate"];
$this->delDate = $row["DelDate"];
$this->priority = $row["Priority"];
$this->operator = $row["Operator"];
$this->addressId = $row["addressId"];
$this->reqIp = $row["Ip"];
$this->reqCountry = $row["Country"];
}
function getItens()
{
$this->total = 0;
$sql = "SELECT * FROM RequestItem WHERE ReqId = '" . $this->reqId . "'";
$this->bd->query($sql) or $this->bd->error($sql);
$this->nItens = $this->bd->numRows();
if(!$this->nItens) return false;
for($i=0; $i < $this->nItens; $i++)
{
$row = $this->bd->fetchRow();
$this->itens[$i] = new RequestItem($this->bd);
$this->itens[$i]->fillAttrib($row);
$this->total +=$this->itens[$i]->price;
}
// C�culo dos intens prontos
$this->setRequestStatus();
$this->nItensDone = $this->searchItemStatus('E') + $this->searchItemStatus('F');
}
//
function searchItemStatus($status)
{
$item = 0;
for($i = 0; $i < $this->nItens; $i++)
if($this->itens[$i]->status == $status) $item++;
return $item;
}
function setRequestStatus()
{
// Setting Request Status
$this->status = 'B';
$minutos = 5;
$nAutorizacao = $nPronto = $nDespachado = $nProb = $nNaoProduzido = 0;
for($i=0; $i < $this->nItens; $i++)
{
switch ($this->itens[$i]->status)
{
case 'A': $nAutorizacao++; break;
case 'E': $nPronto++; break;
case 'F': $nDespachado++; break;
case 'Y': $nProb++; break;
case 'Z': $nProb++; break;
case 'B': if((date( "Y-m-d H:i:s") - $this->itens[$i]->statusDate) > $minutos*60)
{
$nNaoProduzido++;
$this->itens[$i]->updateStatus('W');
}
break;
case 'W': $nNaoProduzido++;
}
}
if(($nPronto + $nDespachado) == $this->nItens) $this->status = 'C';
if($nDespachado == $this->nItens) $this->status = 'D';
if($nAutorizacao) $this->status = 'A';
if($nProb) $this->status = 'Y';
if($nNaoProduzido) $this->status = 'Z';
}
// ??
function getTotal()
{
$this->total=0;
// Get iten's price
for($i = 0; $i < $this->nItens; $i++)
$this->total +=$this->itens[$i]->price();
}
function woGeneration()
{
// Generate one work order for each item
for($i = 0; $i < $this->nItens; $i++)
if(!$this->itens[$i]->woGeneration());
}
function addItem($parNitens=1)
{
$this->nItens+=$parNitens;
}
function subItem($parNitens=1)
{
$this->nItens-=$parNitens;
}
function authorize($numItem=0)
{
if($numItem>0)
{
for($i=0; $i < $this->nItens; $i++)
if($this->itens[$i]->numItem == $numItem)
{
$this->itens[$i]->authorize($this->userId);
break;
}
}
else
for($i=0; $i < $this->nItens; $i++)
$this->itens[$i]->authorize($this->userId);
$this->setRequestStatus();
}
function dispatch($numItem=0)
{
if($numItem>0)
{
for($i=0; $i < $this->nItens; $i++)
if($this->itens[$i]->numItem == $numItem)
{
$this->itens[$i]->dispatch();
break;
}
}
else
for($i=0; $i < $this->nItens; $i++)
$this->itens[$i]->dispatch();
$this->setRequestStatus();
}
function reProduct($numItem=0)
{
if($numItem>0)
{
for($i=0; $i < $this->nItens; $i++)
if($this->itens[$i]->numItem == $numItem)
{
$this->itens[$i]->reProduct($this->userId);
break;
}
}
else
for($i=0; $i < $this->nItens; $i++)
$this->itens[$i]->reProduct($this->userId);
$this->setRequestStatus();
}
function getItemByNumber($nItem)
{
for($i=0; $i < $this->nItens; $i++)
{
if($nItem == $this->itens[$i]->numItem)
return $this->itens[$i];
}
}
function show()
{
echo "<br> REQUEST -> ";
echo $this->userId . " - ";
echo $this->reqDate . " - ";
echo $this->statusDate . " - ";
echo $this->payDate . " - ";
echo $this->delDate . " - ";
echo $this->priority . " - ";
echo $this->nItens . " - ";
echo $this->nItensDone . " - ";
echo $this->itens . " - ";
echo $this->total . " - ";
echo $this->status . " - ";
echo $this->operator . " - ";
echo $this->addressId . " - ";
echo $this->reqIp . " - " ;
echo $this->reqCountry . "<br>";
}
};
//------------------------------------------------------------------------------
// Class RequestItem
//------------------------------------------------------------------------------
class RequestItem
{
var $numItem;
var $reqId;
var $sceneId;
var $productId;
var $bands;
var $sceneShift;
var $correctionLevel;
var $orientation;
var $resampling;
var $datum;
var $projection;
var $longOrigin;
var $latOrigin;
var $stdLat1;
var $stdLat2;
var $format;
var $interleaving;
var $media;
var $price;
var $prodDate;
var $status;
var $statusDate;
var $restoration;
var $bd;
function RequestItem($parbd)
{
$this->numItem = 0;
$this->reqId = 0;
$this->sceneId = "";
$this->productId = "";
$this->bands = "";
$this->sceneShift = 0;
$this->correctionLevel = "";
$this->orientation = "";
$this->resampling = "";
$this->datum = "";
$this->projection = "";
$this->longOrigin = 0;
$this->latOrigin = 0;
$this->stdLat1 = 0;
$this->stdLat2 = 0;
$this->format = "";
$this->interleaving = "";
$this->media = "";
$this->price = "";
$this->prodDate = 0;
$this->status = "";
$this->statusDate=0;
$this->restoration = "";
$this->bd = $parbd;
}
function fill($parReqId, $parScene = "", $parProd="", $parBand="", $parShift=0,
$parCor = "", $parOri="", $parRes="", $parDatum="", $parProj="",
$parLong=0, $parLat=0, $parStd1=0, $parStd2=0, $parFormat="",
$parInter=0, $parMedia="", $parPrice="", $parDate=0, $parStatus='', $parStatusDate=0,$parRestoration="")
{
// Filling requestItem attributes with parameters
$this->reqId = $parReqId;
$this->sceneId = $parScene;
$this->productId = $parProd;
$this->bands = $parBand;
$this->sceneShift = $parShift;
$this->correctionLevel = $parCor;
$this->orientation = $parOri;
$this->resampling = $parRes;
$this->datum = $parDatum;
$this->projection = $parProj;
$this->longOrigin = $parLong;
$this->latOrigin = $parLat;
$this->stdLat1 = $parStd1;
$this->stdLat2 = $parStd2;
$this->format = $parFormat;
$this->interleaving = $parInter;
$this->media = $parMedia;
$this->price = $parPrice;
$this->prodDate = $parDate;
$this->status = $parStatus;
$this->statusDate=$parStatusDate;
$this->restoration=$parRestoration;
}
function insert()
{
// Get today (?)
$this->prodDate = date( "Y-m-d H:i:s" );
// Builds the query statement
$sql = "INSERT INTO RequestItem ";
$sql .= "(ReqId, SceneId, ProductId, Bands, SceneShift,";
$sql .= " CorrectionLevel, Orientation, Resampling, Datum, Projection,";
$sql .= " LongitudeOrigin, LatitudeOrigin, StandardLatitude1, StandardLatitude2, Format,";
$sql .= " Interleaving, Media, Price, Prodate, Status, StatusDate, Restoration) VALUES (";
$sql .= $this->reqId . ", '" . $this->sceneId ."', '";
$sql .= $this->productId . "', '" . $this->bands . "', ";
$sql .= $this->sceneShift . ", '" . $this->correctionLevel . "', '";
$sql .= $this->orientation . "', '" . $this->resampling . "', '";
$sql .= $this->datum . "', '" . $this->projection . "', ";
$sql .= $this->longOrigin . ", " . $this->latOrigin . ", ";
$sql .= $this->stdLat1 . ", " . $this->stdLat2 . ", '";
$sql .= $this->format . "', '" . $this->interleaving . "', '";
$sql .= $this->media . "', " . $this->price . ", '";
$sql .= $this->prodDate . "', '" . $this->status . "', '" . $this->statusDate . "', '" . $this->restoration . "')";
// Does the quer y
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
return true;
}
function modify($parNum=0,$parReqId=0)
{
if($parNum==0) $parNum = $this->numItem;
if($parReqId == 0) $parReqId = $this->reqId;
// Search request
$sql = "UPDATE RequestItem SET ";
$sql .= "SceneId = '" . $this->sceneId . "', ";
$sql .= "ProductId = '" . $this->productId . "', ";
$sql .= "Bands = '" . $this->bands . "', ";
$sql .= "SceneShift = " . $this->sceneShift . ", ";
$sql .= "CorrectionLevel = '" . $this->correctionLevel . "', ";
$sql .= "Orientation = '" . $this->orientation . "',";
$sql .= "Resampling = '" . $this->resampling . "', ";
$sql .= "Datum = '" . $this->datum . "', ";
$sql .= "Projection = '" . $this->projection . "', ";
$sql .= "LongitudeOrigin = " . $this->longOrigin . ", ";
$sql .= "LatitudeOrigin = " . $this->latOrigin . ", ";
$sql .= "StandardLatitude1 = " . $this->stdLat1 . ", ";
$sql .= "StandardLatitude1 = " . $this->stdLat2 . ",";
$sql .= "Format = '" . $this->format . "', ";
$sql .= "Interleaving = '" . $this->interleaving . "', ";
$sql .= "Media = '" . $this->media . "', ";
$sql .= "Price = " . $this->price . ", ";
$sql .= "Prodate = '" . $this->prodDate . "', ";
$sql .= "Status = '" . $this->status . "', ";
$sql .= "StatusDate = '" . $this->statusDate . "', ";
$sql .= "Restoration = ' " . $this->restoration . "'";
$sql .= " WHERE NumItem = " . $parNum . " and ReqId = " . $parReqId;
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
else
return true;
}
function remove($parNum=0,$parReqId=0)
{
// Remove the current Request
if(!$parReqId) $parReqId = $this->reqId;
if(!$parNum) $parNum = $this->numItem;
// Building SQL statement
$sql = "DELETE FROM RequestItem WHERE NumItem = " . $parNum;
$sql .= " and ReqId = " . $parReqId ;
if(!$this->bd->query($sql))
{
$this->bd->error();
return false;
}
else
return true;
}
function search($parNum=0,$parReqId=0)
{
$sql = "SELECT * FROM RequestItem WHERE ReqId = $parReqId";
$this->bd->query($sql) or $this->bd->error($sql);
$nReq = $this->bd->numRows();
if(!$nReq)
{
echo "\n Nenhum item de pedido encontrado! \n";
return 0;
}
$row_array = $this->bd->fetchRow($parNum);
$this->fillAttrib($row_array);
}
function searchItem($parItem=0)
{
$sql = "SELECT * FROM RequestItem WHERE NumItem = $parItem";
$this->bd->query($sql) or $this->bd->error($sql);
$nReq = $this->bd->numRows();
if(!$nReq)
{
echo "\n Nenhum item de pedido encontrado! \n";
return 0;
}
$row_array = $this->bd->fetchRow($nReq);
$this->fillAttrib($row_array);
}
function fillAttrib($row)
{
// Filling requestItem attributes with Data Base field
$this->numItem = $row["NumItem"];
$this->reqId = $row["ReqId"];
$this->sceneId = $row["SceneId"];
$this->productId = $row["ProductId"];
$this->bands = $row["Bands"];
$this->sceneShift = $row["SceneShift"];
$this->correctionLevel = $row["CorrectionLevel"];
$this->orientation = $row["Orientation"];
$this->resampling = $row["Resampling"];
$this->datum = $row["Datum"];
$this->projection = $row["Projection"];
$this->longOrigin = $row["LongitudeOrigin"];
$this->latOrigin = $row["LatitudeOrigin"];
$this->stdLat1 = $row["StandardLatitude1"];
$this->stdLat2 = $row["StandardLatitude2"];
$this->format = $row["Format"];
$this->interleaving = $row["Interleaving"];
$this->media = $row["Media"];
$this->price = $row["Price"];
$this->prodDate = $row["Prodate"];
$this->status = $row["Status"];
$this->statusDate = $row["StatusDate"];
$this->restoration = $row["Restoration"];
}
function updateStatus($parStatus=0)
{
if($parStatus)
$this->status = $parStatus;
else
$this->status++;
$this->statusDate = date( "Y-m-d H:i:s" );
$this->modify();
}
function authorize($parUserId)
{
if($this->status=='A') $this->updateStatus();
$this->execute($parUserId);
}
function dispatch()
{
if($this->status=='E') $this->updateStatus();
}
function reProduct($parUserId)
{
if($this->status=='W') $this->updateStatus('B');
//$this->execute($parUserId);
}
function getItemStatus()
{
return $this->status;
}
function woGeneration()
{
// Retrive scene data
//$objScene = new Scene();
//$objScene->search($this->sceneId);
// Verify if order for product or order for production
//if((trim($this->productId)=="")
//{
}
function execute($parUserId)
{
// Arrays
require ("arrays.php");
//Verify item status
if($this->status != 'B' and $this->status != 'Q') return 1;
// Flags
$inproduction = true;
// Searching Scene
$sql = "SELECT * FROM Scene WHERE SceneId='". $this->sceneId ."'";
$this->bd->query($sql) or die("<br> Error on execution/result sql = $sql <br>");
$itens = $this->bd->numRows();
if ($itens == 0) die("Erro nas Cenas");
$row = $this->bd->fetchRow();
$this->bd->freeResult($results);
// Scene data
$res = explode(".",$row["SceneId"]);
$sufix = $res[1];
$satCod = $row["Satellite"];
$sensor = $row["Sensor"];
if($satCod == "P6" and ($sensor == "LIS3" or $sensor == "AWIF"))
{
$date_IRS = $row["Date"];
$path_IRS = $row["Path"];
$row_IRS = $row["Row"];
}
for($i=0; $i<$matSatCod[0]; $i++) if($satCod == $matSatCod[$i]) break;
$satName = $matSatName[$i];
$taName = $satName . "Scene";
if ($GLOBALS["stationDebug"]) echo "\n RequestClass - Satelite = " . $satName . " TabName = " . $taName . " UserName = " .
$parUserId . "\n";
//Finding Gralha/Fred
$sql = "SELECT * FROM $taName WHERE SceneId='".$this->sceneId ."'";
if ($GLOBALS["stationDebug"]) echo "RequestClass - Sql Command: ". $sql ."\n";
$this->bd->query($sql);
$row = $this->bd->fetchRow() or die("<br> Error on execution/result sql = $sql <br>");
$file = $row["Gralha"];
$this->bd->freeResult();
if ($GLOBALS["stationDebug"]) echo "RequestClass - File = " . $file . "\n";
// Creating p2u argument
$argument = $parUserId .";". $this->reqId . ";".$this->sceneId.";".$file.";".$this->numItem.";".$this->restoration;
$procPar = 0;
if ($GLOBALS["stationDebug"]) echo "RequestClass - Argument = " . $argument . "\n";
// Instantiating P2 class
searchMedia($this->bd, $objMedia, $this->media);
$execClass = $objMedia[0]->getExecClass();
if ($GLOBALS["stationDebug"]) echo "1 - RequestClass - starting P2U or P2C = " . $execClass . "\n";
if($satCod == "P6" and ($sensor == "LIS3" or $sensor == "AWIF"))
{
include_once ("listFiles.php");
if($sensor == "LIS3") $sensor = "LISS3"; // That's for the STUPID modification done (renaming LIS3 for LISS3 and AWIF for AWIFS) at CDSR.
else $sensor = "AWIFS";
$dir_path = getTiffDir($satCod);
$res = explode("-", $date_IRS);
$date_dir = $res[0] . "_" . $res[1];
$date_aux = $res[0] . $res[1] . $res[2];
$tiff_dir = $dir_path . "$date_dir/$satCod" . "_$sensor" . "_$date_aux/$path_IRS" . "_$row_IRS";
// $tiffs = listFiles2($tiff_dir,"");
// $cmd = "ls -1 $tiff_dir";
// $res = shell_exec($cmd);
// $tiffs = explode("\n",$res);
$aux_tiffs = glob($tiff_dir . "/*");
$index = 0;
foreach ($aux_tiffs as $file)
{
$tiffs[$index] = basename($file);
$index ++;
};
print_r ($tiffs);
$argument = $parUserId .";". $this->reqId . ";".$this->sceneId.";".$tiff_dir.";".$this->numItem.";".$satCod;
if ($GLOBALS["stationDebug"]) echo "RequestClass ====> starting P2U for P6 products - Argument = $argument \n";
if ($GLOBALS["stationDebug"])echo "\n RequestClass =====> tifdir = $tiff_dir \n";
$p2u = new p2u($argument);
}
else
// GLS
// ===
if($sufix == "GLS")
{
$sql = "SELECT Gralha FROM LandsatScene WHERE SceneId='". $this->sceneId ."'";
$this->bd->query($sql) or die("<br> Error on execution/result sql = $sql <br>");
$itens = $this->bd->numRows();
if ($itens == 0) die("Erro nas Cenas");
$row = $this->bd->fetchRow();
$this->bd->freeResult($results);
$gralha = $row["Gralha"];
decodeGralha($gralha,$satellite,$number,$instrument,$channel_gralha,$type,$date,$path,$row);
if($number == 5) $sat_prefix = "LT5";
else $sat_prefix = "LE7";
$year = substr($date,0,4);
$timestamp = strtotime($date);
$julian_date = strftime('%j', $timestamp);
$sql = "SELECT Dataset FROM Scene WHERE SceneId='".$this->sceneId ."'";
if ($GLOBALS["stationDebug"]) echo "\n =====> RequestClass - Sql Command: ". $sql ."\n";
$this->bd->query($sql);
$row_result = $this->bd->fetchRow() or die("\n =====> Request.Class - execute ====> Error on execution/result sql = $sql \n");
$dataset = $row_result["Dataset"];
$this->bd->freeResult();
if($dataset == "GLS2000") $target_tiffs = "*" . $path . "*" . $row . "*" . $date . "*.tar.gz"; // For GLS2000 tar.gz, file titles have a different format (syntax)
else $target_tiffs = "*" . $path . "*" . $row . "*" . $year . $julian_date . "*.tar.gz" ;
$dir_path = getTiffDir($sufix);
$tiff_dir = $dir_path . $satellite . $number ;
$cmd= "find $tiff_dir -name $target_tiffs";
$cmd = addslashes($cmd);
echo "\n =====> Request.Class - execute ====> com = $cmd \n";
$output = shell_exec($cmd);
$output = substr($output,0,strlen($output)-1);
if($output == "") die("\n =====> Request.Class - execute ====> No files : $target_tiffs !");
$tiffs = explode("\n",$output);
sort($tiffs);
echo "\ntiffs = \n";
print_r($tiffs);
echo "\n";
$argument = $parUserId . ";" . $this->reqId . ";" . $this->sceneId . ";" . $tiffs[0] . ";" . $this->numItem . ";" . $sufix;
echo "\nargument = \n";
print_r($argument);
echo "\n";
$p2u = new p2u($argument);
// echo "\n<br> argument = $argument";
}
else
{
$p2u = new $execClass($argument);
$tiffs = $p2u->getTiffs ();
};
// print_r($tiffs);
// For generation of a product
if($sensor == "CCD")
{
$bands_all = array(0 => "5", 1 => "BAND1", 2 => "BAND2", 3 => "BAND3", 4 => "BAND4", 5 => "BAND5");
$bands_lacking = 0;
foreach($tiffs as $tiff_found)
{
$one_tiff = basename($tiff_found);
for($i=1; $i <= $bands_all[0]; $i++)
{
$found = strstr($one_tiff,$bands_all[$i]);
if($found)
{
$bands_all[$i] = 1;
$bands_lacking += 1;
}
}
}
for($i=1; $i < 6 ; $i++)
if($bands_all[$i] != 1) $bands_lacking += 1;
}
if($sensor != "CCD") $factor = 1;
else
if($bands_lacking > 0) $factor = 6; // If instrument = CCD we must deliver all 5 bands.
else $factor = 5; // We could have two repeated bands 3 (CCD1XS and CCD2XS), plus bands 1,2 and 4, and no PAN, and we would have 5 bands on directory!
// if(trim($this->productId)== "" and count($tiffs) < $factor)
if(count($tiffs) < $factor)
{
// Tiff does not exist in disk, lets build it from gralha
if ($GLOBALS["stationDebug"]) echo "RequestClass - Tiff not found, looking for $file\n";
$gralhas = findSimilarGralhainDisk ($file);
$count_gralhas = count($gralhas);
if($count_gralhas > 0 or count($tiffs) > 0) // we may have some CCD Tiffs but some Gralha may not be present on disk.
{
$gralhas_files = array(0 => "CCD1XS", 1 => "CCD2XS", 2 => "CCD2PAN");
foreach($gralhas as $filedir)
{
if ($GLOBALS["stationDebug"]) echo "<br> \n RequestClass - $filedir found <br> \n";
if($sensor == "CCD")
{
decodeGralha(basename($filedir),$satellite,$number,$instrument,$channel,$type,$date,$path,$row);
$this_gralha_tiffs = findTiffinDiskFromGralha (basename($filedir),$this->restoration,$channel); // look for specific (Channel) Tiff data
switch($type)
{
case "XS":
if($channel == 1) $gralhas_files[0] = "1"; // Gralha CCD1XS present
else $gralhas_files[1] = "1"; // Gralha CCD2XS present
break;
case "PAN":
$gralhas_files[2] = "1"; // Gralha CCD2PAN present
}
if(count($this_gralha_tiffs) == 0) $procPar = $this->g2tStart($filedir,$procPar,$satCod);
}
else
{
if($sensor == "ETM")
{
$filepan = str_replace("XS","PAN",$filedir);
$procPar = $this->g2tStart($filepan,$procPar,$satCod);
}
$procPar = $this->g2tStart($filedir,$procPar,$satCod);
}
}
if($sensor == "CCD")
for($i=0; $i < 3 ; $i++)
if($gralhas_files[$i] != "1") // Gralha not present; let's verify Tiffs
{
$gralha_name = str_replace("CCD1XS", $gralhas_files[$i], $file); // CCD1XS is the reference for Gralha in CbersScene
decodeGralha($gralha_name,$satellite,$number,$instrument,$channel,$type,$date,$path,$row);
$tiffs_found = findTiffinDiskFromGralha($gralha_name,$this->restoration,$channel); // look for specific (Channel) Tiff data
if(count($tiffs_found) == 0) // Generate corresponding Gralha and then Tiffs
{
$status = findDRDfromSceneId ($this->sceneId,$drds,$tapeid,$tapepath,$skip);
if($status == 0) // DRD is registered in database
{
if($gralhas_files[$i] == "CCD1XS") $index = 0; // Corresponds to DRD[0]
else $index = 1; // Corresponds to DRD[1] (CCD2XS and CCD2PAN)
$fulldrd = findDRDinDisk($drds[$index]);
if(strlen($fulldrd) > 1)
{
$d2g = new d2g ($drds[$index]);
$d2g->createWorkOrder();
$d2g->start($procPar);
$procPar = $this->g2tStart($gralha_name,$d2g->id(),$satCod);
$gralhas_files[$i] = "1";
} else $inproduction = false;
}else $inproduction = false;
} else $gralhas_files[$i] = "1"; // Gralha not present but Tiffs are !!! That's what matters !!!
}
} else
//if Gralha does not exist, generate it from DRD
{
if ($GLOBALS["stationDebug"]) echo "<br> RequestClass - Gralhas not found, looking for DRD\n";
$status = findDRDfromSceneId ($this->sceneId,$drds,$tapeid,$tapepath,$skip);