-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.inc.php
executable file
·1624 lines (1447 loc) · 48.5 KB
/
db.inc.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
/**
* This file is part of the RPCL project
*
* Copyright (c) 2004-2011 Embarcadero Technologies, Inc.
*
* Checkout AUTHORS file for more information on the developers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*/
use_unit("classes.inc.php");
use_unit("rtl.inc.php");
/**
* Base class for connection components, that is, components that perform a connection to a data provider (e.g. to a
* database management system).
*
* This class provides the methods used by data access components (Table, Query, etc.) to retrieve data. The class acts
* like an interface that determines the properties and methods expected by data access components, which must be
* implemented in child classes, such as Database.
*/
class CustomConnection extends Component
{
protected $_fstreamedconnected=false;
// LIFECYCLE
// Documented in the parent.
function __construct($aowner=null)
{
//Calls inherited constructor
parent::__construct($aowner);
}
// Documented in the parent.
function loaded()
{
parent::loaded();
if ($this->_fstreamedconnected)
{
$this->Connected = true;
}
}
// PROPERTIES
/**
* Whether the connection is open ("1") or closed ("0").
*/
function readConnected() { return "0"; }
function writeConnected($value)
{
if (($this->ControlState & csLoading)==csLoading)
{
$this->_fstreamedconnected=$value;
}
else
{
// prevent to execute when the current is for javascript or css
if (isset($_GET['css']) || isset($_GET['js'])){
return;
}
if ($value == $this->readConnected())
{
// silent is gold...
}
else
{
if ($value)
{
$this->callEvent("onbeforeconnect",array());
$this->DoConnect();
$this->callEvent("onafterconnect",array());
}
else
{
$this->callEvent("onbeforedisconnect",array());
$this->DoDisconnect();
$this->callEvent("onafterdisconnect",array());
}
}
}
}
protected $_drivername="";
/**
* Name of the driver to be used for the connection.
*/
function readDriverName() { return $this->_drivername; }
function writeDriverName($value) { $this->_drivername=$value; }
function defaultDriverName() { return ""; }
// EVENTS
protected $_onbeforeconnect = null;
/**
* Triggered before the connection is established.
*/
function readOnBeforeConnect() { return $this->_onbeforeconnect; }
function writeOnBeforeConnect($value) { $this->_onbeforeconnect=$value; }
function defaultOnBeforeConnect() { return null; }
protected $_onafterconnect = null;
/**
* Triggered after the connection has been established.
*/
function readOnAfterConnect() { return $this->_onafterconnect; }
function writeOnAfterConnect($value) { $this->_onafterconnect=$value; }
function defaultOnAfterConnect() { return null; }
protected $_onbeforedisconnect = null;
/**
* Triggered before the connection is closed.
*/
function readOnBeforeDisconnect() { return $this->_onbeforedisconnect; }
function writeOnBeforeDisconnect($value) { $this->_onbeforedisconnect=$value; }
function defaultOnBeforeDisconnect() { return null; }
protected $_onafterdisconnect = null;
/**
* Triggered after the connection has been closed.
*/
function readOnAfterDisconnect() { return $this->_onafterdisconnect; }
function writeOnAfterDisconnect($value) { $this->_onafterdisconnect=$value; }
function defaultOnAfterDisconnect() { return null; }
// METHODS
/**
* Opens the conection.
*/
function Open()
{
$this->Connected = true;
}
/**
* Closes the connection.
*/
function Close()
{
$this->Connected = false;
}
/**
* Executes the given query against the data provider.
*
* <code>
* $results = $customConnection->execute("SELECT something FROM somewhere WHERE somethingElse = ".$customConnection->param("number"), array(6));
* </code>
*
* @param string $query Query.
* @param array $params Array of parameters to be passed along with the query.
*
* @return mixed The return value depends on the implementation.
*/
function execute($query, $params = array()){}
/**
* Returns a query object for the given $query. You can usually then run the query against the data provider by
* calling the execute() method on the query object.
*
* <code>
* $selectQuery = $customConnection->prepare("SELECT something FROM somewhere");
* // Do implementation-specific operations on the query object, such as binding paramenters, etc.
* $results = $selectQuery->execute();
* </code>
*
* @param string $query
*
* @return mixed
*/
function prepare($query){}
/**
* Returns a place holder for a patameter that can be used in a query string. The place holder will later be
* replaced by the actual parameter when executing the query.
*
* <code>
* $results = $customConnection->execute("SELECT something FROM somewhere WHERE somethingElse = ".$customConnection->param("number"), array(6));
* </code>
*
* @param mixed $input The purpose of this parameter depends on the actual implementation. Some implementations
* might ignore this parameter altogether, and just associate the parameters to the place
* holders in base to their order in the array of parameters.
*
* @return string Place holder.
*/
function param($input){}
/**
* Returns the given value quoted so it can be safely used in a query string.
*
* <code>
* $result = $customConnection->execute("SELECT something FROM somewhere WHERE somethingElse != ".$customConnection->quoteStr($_POST["userInput"]));
* </code>
*
* @param mixed $imput Value to be quoted.
*
* @return string Quoted value.
*/
function quoteStr($input){}
/**
* Begins a transaction against the data provider.
*
* After calling this method, further operations on the data at the other point of the connection will be held until
* a call to completeTrans(), which will perform those operations altogether.
*
* <code>
* $customConnection->beginTrans();
* $customConnection->execute("INSERT INTO somewhere (field) VALUES (".$customConnection->param("value").")", array("Some value"));
* $customConnection->execute("INSERT INTO somewhere (field) VALUES (".$customConnection->param("value").")", array("Another value"));
* $customConnection->completeTrans(); // The execute() operations are not actually executed until this point.
* </code>
*
* @return mixed The return value will depend on the implementation.
*/
function beginTrans(){}
/**
* Finishes a transaction started with beginTrans(), either commiting all the operations on the data provider that
* were requested since the transaction started ($commit = true, default), or rolling them back so none of them are
* actually performed against the data provider ($commit = false).
*
* <code>
* $customConnection->beginTrans();
* $insertResult1 = $customConnection->execute("INSERT INTO somewhere (field) VALUES (".$customConnection->param("value").")", array("Some value"));
* $insertResult2 = $customConnection->execute("INSERT INTO somewhere (field) VALUES (".$customConnection->param("value").")", array("Another value"));
* $commit = $insertResult1 && $insertResult2; // Evaluates to false if any of the operations failed.
* $customConnection->completeTrans($commit);
* </code>
*
* @param bool $commit Whether the operations in the transaction should be commited (true) or rolled back (false).
*
* @return mixed The return value will depend on the implementation.
*/
function completeTrans($commit = true){}
/**
* Establishes the connection to the data provider if it was not established already.
*/
function doConnect(){}
/**
* Terminates the connection to the data provider if it was established.
*/
function doDisconnect(){}
/**
* Whether or not there is an ongoing transaction.
*
* @return bool
*/
function inTransaction(){}
}
define('dsInactive' ,1);
define('dsBrowse' ,2);
define('dsEdit' ,3);
define('dsInsert' ,4);
define('daFail' ,1);
define('daAbort' ,2);
/**
* Class for exceptions related to databases.
*
* Rather than creating and raising an instance of thsi exception, consider calling the databaseError() function for a
* cleaner code.
*/
class EDatabaseError extends Exception { }
/**
* Raises an EDatabaseError exception.
*
* @param string $message Error message.
* @param Component $component Component instance that is raising the exception (optional).
*
* @throw EDatabaseError
*/
function databaseError($message, $component=null)
{
if ((assigned($component)) && ($component->Name != ''))
{
throw new EDatabaseError(sprintf('%s: %s', $component->Name, $message));
}
else
{
throw new EDatabaseError($message);
}
}
/**
* This class defines the common methods and properties to work with a collection of data (dataset), no matter how the
* data is stored.
*
* Child classes might encapsulate access to a simple array in memory, a text file in disk, or even a query on a
* database.
*
* @link wiki://DataSet_Components
*/
class DataSet extends Component
{
protected $_fstreamedactive = false;
// LIFECYCLE
// Documented in the parent.
function loaded()
{
parent::loaded();
$this->writeMasterSource($this->_mastersource);
$this->Active = $this->_fstreamedactive;
}
// Documented in the parent.
function serialize()
{
parent::serialize();
if ( $owner = $this->readOwner() )
{
$prefix = $owner->readNamePath().".".$this->_name.".";
// restore the state
$_SESSION[$prefix."State"] = $this->_state;
}
}
// Documented in the parent.
function unserialize()
{
parent::unserialize();
if ($owner = $this->readOwner())
{
$prefix = $owner->readNamePath().".".$this->_name.".";
if (isset($_SESSION[$prefix."State"]))
{
$this->_state = $_SESSION[$prefix."State"];
}
}
}
// PROPERTIES
protected $_active = false;
/**
* Whether the dataset is open (true) or closed (false). You cannot work on a closed dataset.
*
* @return bool
*/
function readActive()
{
return $this->_active;
}
function writeActive($value)
{
if (($this->ControlState & csLoading) == csLoading)
{
$this->_fstreamedactive = $value;
}
else
{
// prevent to execute when the current is for javascript or css
if (isset($_GET['css']) || isset($_GET['js'])){
// emulates the setter
$this->_active = $value;
return;
}
if ($this->_active != $value)
{
try
{
if ($value == true)
{
// this if for internal use
$this->_bof = true;
$this->_eof = true;
$this->callevent("onbeforeopen",array());
$this->internalOpen();
// if the state is stored in session, restore it
if ($this->_state == dsInactive)
$this->_state = dsBrowse;
// opened successful
$this->_active = true;
$this->callevent("onafteropen",array());
}
else
{
$this->_active = false;
$this->callevent("onbeforeclose",array());
$this->internalClose();
$this->_state = dsInactive;
$this->callevent("onafterclose",array());
}
}catch(Exception $e)
{
$this->State = dsInactive;
throw $e;
}
}
}
}
protected $_bof = false;
/**
* Whether the current record is the first record of the dataset (true) or not (false).
*
* @return bool
*/
function readBOF() { return $this->_bof; }
function defaultBOF() { return false; }
protected $_canmodify=true;
/**
* Whether the dataset can be modified (true) or it is read-only (false).
*
* @return bool
*/
function readCanModify() { return $this->_canmodify; }
function writeCanModify($value) { $this->_canmodify=$value; }
function defaultCanModify() { return true; }
protected $_eof = false;
/**
* Whether the current record is the last record of the dataset (true) or not (false).
*
* @return bool
*/
function readEOF() { return $this->_eof; }
function defaultEOF() { return false; }
protected $_fieldbuffer=array();
/**
* Associative array of key-value pairs describing the content (field-value) of the current record in the underlying
* storage system.
*
* Any change to the current record that has not been posted yet will not be reflected in this array.
*
* @see readFields()
*
* @return array
*/
function readFieldBuffer(){ return $this->_fieldbuffer;}
/**
* Number of fields of the current record.
*
* @return int
*/
function readFieldCount() { return 0; }
/**
* Associative array of key-value pairs describing the content (field-value) of the current record in the dataset.
*
* Any change to the current record will be reflected in this array, even if it has not been posted to the
* underlying storage system yet.
*
* @see readFieldBuffer()
*
* @return array
*/
function readFields() { return array(); }
protected $_filter="";
/**
* Filter to be applied when retrieving records from the data provider. Only the records matching the conditions
* defined in the filter will be retrieved and available in the dataset.
*/
function readFilter() { return $this->_filter; }
function writeFilter($value){$this->_filter=$value;}
function defaultFilter() { return ""; }
protected $_limitcount='';
/**
* Number of records from the data provider to be provided by the dataset.
*
* For example, if this property is set to "10", the dataset will only contain 10 records from the data provider.
*
* @see getLimitStart()
*
* @return string
*/
function getLimitCount() { return $this->_limitcount; }
function setLimitCount($value) { $this->_limitcount=$value; }
function defaultLimitCount() { return "10"; }
protected $_limitstart='';
/**
* Number of records from the data provider to be skipped in the dataset, from the start.
*
* For example, if this property is set to "10", the first record in the dataset will be the 11th record from the
* data provider.
*
* @see getLimitCount()
*
* @return string
*/
function getLimitStart() { return $this->_limitstart; }
function setLimitStart($value) { $this->_limitstart=$value; }
function defaultLimitStart() { return "0"; }
protected $_masterfields=array();
/**
* Associative array of key-value pairs, where the 'key' is the name of a field in this dataset, and the 'value' is
* the name of a field from the MasterSource. This association is used to filter the records retrieved from the data
* provider into the dataset.
*
* Suppose you have two datasets, named MasterDataSet and SlaveDataSet, where SlaveDataSet (this dataset) has
* MasterDataSet associated to its MasterSource property (MasterSource = $MasterDataSet), and SlaveDataSet's
* MasterFields property is defined as array('category_id' => 'id').
*
* As a result of the configuration above, SlaveDataSet would only contain records whose 'category_id' field has the
* same value as the 'id' field of the current record of the MasterDataSet.
*
* @see readMasterSource()
*
* @return array
*/
function readMasterFields() { return $this->_masterfields; }
function writeMasterFields($value) { $this->_masterfields=$value; }
function defaultMasterFields() { return array(); }
protected $_mastersource=null;
/**
* Instance of DataSet to be used to filter the records that this dataset retrieves from the data provider.
*
* This property must be used in combination with MasterFields, else it is useless.
*
* @see readMasterFields()
*
* @return DataSet
*/
function readMasterSource() { return $this->_mastersource; }
function writeMasterSource($value)
{
$this->_mastersource=$this->fixupProperty($value);
}
protected $_modified = false;
/**
* Whether the current record has been modified (true) or not (false). For new records, this function returns true
* when any of its fields has been given a value.
*
* @return bool
*/
function readModified() { return $this->_modified; }
function writeModified($value) { $this->_modified=$value; }
function defaultModified() { return false; }
protected $_recno=0;
/**
* Number that represents the position of the current record in the dataset.
*
* Change this property to navigate to a record in a different position.
*
* @return int
*/
function readRecNo() { return $this->_recno; }
function writeRecNo($value)
{
if ($value != $this->_recno)
{
$diff = $value - $this->_recno;
if ($diff > 0)
{
$this->moveBy($diff);
}
$this->_recno = $value;
}
}
function defaultRecNo() { return 0; }
protected $_recordcount = 0;
/**
* Total number of records in the dataset.
*
* @return int
*/
function readRecordCount() { return $this->_recordcount; }
function defaultRecordCount() { return 0; }
protected $_state = dsInactive;
/**
* Current state of the dataset.
*
* 'dsInactive' indicates the dataset is closed. 'dsBrowse' is the standard state when the dataset is open. 'dsEdit'
* indicates that a record of the dataset is being modified. 'dsInsert' indicates that a new record, to be added to
* the dataset, is being defined.
*
* @return int
*/
function readState() { return $this->_state; }
function writeState($value) { $this->_state=$value; }
function defaultState() { return dsInactive; }
// EVENTS
protected $_onnewrecord=null;
/**
* Triggered once a new record has been added to the dataset (not to the underlying database).
*
* The new record might have been added by starting either an append or an insert operation.
*
* You may use this event to make some changes to the new record that will not count as a modification, so the
* record won't be commited to the underlying database unless it is further modified later, or you call
* completeTrans().
*
* @see append(), insert()
*/
function readOnNewRecord() { return $this->_onnewrecord; }
function writeOnNewRecord($value) { $this->_onnewrecord=$value; }
function defaultOnNewRecord() { return null; }
// METHODS
/**
* Opens the dataset. When a dataset is opened, it gets filled with the records from its data provider.
*
* @see close()
*/
function open()
{
$this->Active = true;
}
/**
* Closes the dataset. The dataset will be emptied of records, and you won't be able to work with the dataset until
* you open it again.
*
* @see open()
*/
function close()
{
$this->Active = false;
}
/**
* Begins an insert operation for the current record.
*
* In an insert operation, you define a new record by modifying the data in the current record, and then you add
* that new record to the dataset.
*
* For example, imagine you have a dataset with the fields Name and Surname, and for those fields, the current record
* has the values 'Jane' and 'Doe' respectively. You could use this method to insert a new record in the dataset
* changing just the Name, and reusing the Surname of the current record:
*
* <code>
* $dataSet->insert();
* $dataSet->Name = 'John';
* $dataSet->post();
* </code>
*
* Now the dataset would have both a record for Jane Doe and a record for John Doe.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method. Imagine the
* following code was used instead of the three statements above:
*
* <code>
* $dataSet->insert();
* $dataSet->Name = 'John';
* $dataSet->insert();
* $dataSet->Name = 'Jack';
* $dataSet->post();
* </code>
*
* Then the dataset would have records for Jane Doe, John Doe and Jack Doe.
*
* You can use this feature to insert records with values in common to the current record using a loop like this:
*
* <code>
* $names = array('John', 'Jake', 'Jennifer', 'James', 'Judy');
* foreach ($names as $name)
* {
* $dataSet->insert();
* $dataSet->Name = $name;
* }
* $dataSet->post();
* </code>
*
* @see append(), cancel(), edit(), post()
*/
function insert()
{
$this->beginInsertAppend();
$this->internalInsert();
$this->endInsertAppend();
}
/**
* Begins an append operation for the current record.
*
* In an append operation, you define a brand new record, and then you add it to the dataset.
*
* For example, imagine you have a dataset with the fields Name and Surname. This is how you would add a new record
* to it:
*
* <code>
* $dataSet->append();
* $dataSet->Name = 'Jane';
* $dataSet->Surname = 'Doe';
* $dataSet->post();
* </code>
*
* Now the dataset would have a new record for Jane Doe.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method. Imagine the
* following code was used instead of the four statements above:
*
* <code>
* $dataSet->append();
* $dataSet->Name = 'John';
* $dataSet->Surname = 'Doe';
* $dataSet->append();
* $dataSet->Name = 'Jane';
* $dataSet->Surname = 'Doe';
* $dataSet->post();
* </code>
*
* Then the dataset would have two new records, one for John Doe and another one for Jane Doe.
*
* You can use this feature to append records to the dataset in a loop like this:
*
* <code>
* $names = array('John' => 'Doe', 'Jane' => 'Doe');
* foreach ($names as $name => $surname)
* {
* $dataSet->append();
* $dataSet->Name = $name;
* $dataSet->Surname = $surname;
* }
* $dataSet->post();
* </code>
*
* @see cancel(), insert(), post()
*/
function append()
{
$this->beginInsertAppend();
$this->clearBuffers();
$this->initRecord();
$this->internalInsert();
$this->endInsertAppend();
}
/**
* Removes the current record from the dataset.
*/
function delete()
{
$this->checkActive();
if (($this->State==dsInsert))
{
$this->Cancel();
}
else
{
if ($this->_recno == 0)
DatabaseError(_("Cannot perform this operation on an empty dataset"), $this);
// event before
$this->callevent("onbeforedelete",array());
// try delete
try
{
$this->internalDelete();
$this->freeFieldBuffers();
$this->State = dsBrowse;
}
catch(Exception $e)
{
$this->callEvent('ondeleteerror', array('Exception'=>$e, 'Action'=>'internalDelete'));
}
// event after
$this->callevent("onafterdelete",array());
}
}
/**
* Begins an edit operation for the current record.
*
* In an edit operation, you modify the data in the current record, and then update the dataset with those changes.
*
* For example, imagine you have a dataset with the fields Name and Surname, and for those fields, the current record
* has the values 'Jane' and 'Doe' respectively. You could use this method to change the Name of the record:
*
* <code>
* $dataSet->edit();
* $dataSet->Name = 'John';
* $dataSet->post();
* </code>
*
* Now the dataset record for Jane Doe would be replaced by a record for John Doe.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method.
*
* <code>
* $dataSet->append();
* $dataSet->Name = 'John';
* $dataSet->Surname = 'Doe';
* $dataSet->edit(); // The append operation stops and the new record, for John Doe, is added to the dataset.
* $dataSet->Name = 'Jane';
* $dataSet->post(); // The Name of the record, which was already in the dataset, is changed to 'Jane'.
* </code>
*
* @see cancel(), insert(), post()
*/
function edit()
{
if ($this->State == dsEdit || $this->State == dsInsert)
{
return;
}
$this->checkBrowseMode();
$this->checkCanModify();
$this->callevent("onbeforeedit",array());
$this->checkOperation("internalEdit", "onediterror");
$this->State = dsEdit;
$this->callevent("onafteredit",array());
}
/**
* Points the record cursor to the first record in the dataset.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method.
*
* <code>
* $dataSet->edit();
* $dataSet->Name = 'Jane';
* $dataSet->first();
* </code>
*
* When you call first(), the Name of the current record is changed to 'Jane' in the dataset, and then the record
* cursor is moved to the first record.
*/
function first()
{
$this->checkBrowseMode();
if(!$this->BOF)
{
// no directional dataset (reopen)
if ($this->isUnidirectional())
{
$this->Active = false;
$this->Active = true;
}
// direcctional dataset
else
{
$this->clearBuffers();
$this->internalFirst();
}
$this->_eof = false;
$this->_bof = true;
}
}
/**
* Points the record cursor to the last record in the dataset.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method.
*
* <code>
* $dataSet->edit();
* $dataSet->Name = 'Jane';
* $dataSet->last();
* </code>
*
* When you call last(), the Name of the current record is changed to 'Jane' in the dataset, and then the record
* cursor is moved to the last record.
*/
function last()
{
$this->checkBidirectional();
$this->checkBrowseMode();
if (!$this->EOF)
{
$this->clearBuffers();
// implement in child class
$this->internalLast();
$this->_eof = true;
$this->_bof = false;
}
}
/**
* Points the record cursor to the next record in the dataset.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method.
*
* <code>
* $dataSet->edit();
* $dataSet->Name = 'Jane';
* $dataSet->next();
* </code>
*
* When you call next(), the Name of the current record is changed to 'Jane' in the dataset, and then the record
* cursor is moved to the next record.
*/
function next()
{
$this->moveBy(1);
}
/**
* Points the record cursor to the previous record in the dataset.
*
* Any unsaved changes to the current record will be saved to the dataset upon calling this method.
*
* <code>
* $dataSet->edit();
* $dataSet->Name = 'Jane';
* $dataSet->prior();
* </code>
*
* When you call prior(), the Name of the current record is changed to 'Jane' in the dataset, and then the record
* cursor is moved to the previous record.
*/
function prior()
{
$this->moveBy(-1);
}
/**
* Reloads the dataset with the records from the data provider.
*/
function refresh()
{
$this->Active = false;
$this->Active = true;
}
/**
* Moves the record cursor the given number of positions. Use negative values to move the cursor backwards.
*
* For example, if the current record of the dataset is the 6th:
*
* <code>
* $dataSet->moveBy(2); // The 8th is now the current record.
* $dataSet->moveBy(-5); // The 3rd is now the current record (8 - 5 = 3).
* </code>
*
* The movement goes as far as it can. If you provide a number that would take the cursor to a position outside of
* the range of records, the cursor will be moved just until the limit (the first or the last record).
*
* For example, if you are in the 10th of the 30 records the dataset has:
*