forked from doxbox/doxbox-dms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbmodify.php
executable file
·4420 lines (3944 loc) · 167 KB
/
dbmodify.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
/**
* dbmodify.php
*
* Author: Steve Bourgeois <[email protected]>
*
* Copyright (c) 2006-2009 Bozz IT Consulting Inc
*
* Licensed under the GNU GPL. For full terms see the file LICENSE.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: dbmodify.php,v 1.57 2006/09/15 15:08:52 b0zz Exp $
*/
// Functions to read XML post data from ubr_upload
function startElement($parser, $name, $attrs) {
global $curTag;
$curTag .= "^$name";
}
function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}
function characterData($parser, $data) {
global $curTag;
global $qstr;
if (substr($curTag, 0, 16) == "^uu_upload^post^")
{
$qstr .= "&".substr($curTag,strrpos($curTag,'^')+1)."=".$data;
}
if (substr($curTag, 0, 28) == "^uu_upload^file^file_upload^")
{
$qstr .= "&file_".substr($curTag,strrpos($curTag,'^')+1)."=".$data;
}
}
ob_start();
require_once(dirname(__FILE__) ."/config/owl.php");
$out = ob_get_clean();
if ($default->use_ubr_progress_bar == 1)
{
// main loop
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$uFile = $default->ubr_progress_bar_tmp_dir."/".$_GET['upload_id'].".redirect";
if (file_exists($uFile)) {
// read the contents of the redirect file
$strXML = implode("",file($uFile));
// parse the redirect file
xml_parse($xml_parser, $strXML);
// clean up - we're done
xml_parser_free($xml_parser);
$qstr = ereg_replace("ARRAY=","[]=", $qstr);
//parse_str($qstr);
parse_str($qstr, $_POST);
}
}
elseif ($default->use_progress_bar == 1)
{
$sid = $_GET['sid'];
if (file_exists($default->progress_bar_tmp_dir . "/{$sid}_qstring"))
{
$qstr = join("",file($default->progress_bar_tmp_dir . "/{$sid}_qstring"));
//parse_str($qstr);
parse_str($qstr, $_POST);
}
}
require_once($default->owl_fs_root ."/lib/disp.lib.php");
require_once($default->owl_fs_root ."/lib/xtpl.lib.php");
require_once($default->owl_fs_root ."/lib/owl.lib.php");
require_once($default->owl_fs_root ."/lib/security.lib.php");
require_once($default->owl_fs_root ."/scripts/phpmailer/class.phpmailer.php");
require_once($default->owl_fs_root ."/lib/pclzip/pclzip.lib.php");
// Code to Handle Document Type page refresh
if (!isset($action))
{
$action = '';
}
if ($default->use_ubr_progress_bar == 1 && ($action == "file_upload" or $action == "zip_upload") && $type == "")
{
$userfile['name'] = file_basename($file_name);
$userfile['size'] = $file_size;
$userfile['tmp_name'] = $default->ubr_progress_bar_upload_dir . "/" . $userfile['name'];
}
if (($action == "file_upload" or $action == "zip_upload") and !isset($send_file_x) and $default->use_ubr_progress_bar == 0)
{
header("Location: " . $default->owl_root_url . "/modify.php?sess=$sess&action=$action&parent=$parent&expand=$expand&order=$order&sortname=$sort&doctype=$doctype&type=$type");
exit;
}
// Code to handle the click on the bulk action
// image button;
if (isset($bemailaction_x))
{
$action = $owl_lang->email_selected;
} elseif (isset($bmoveaction_x))
{
$action = $owl_lang->move_selected;
} elseif (isset($bcheckout_x))
{
$action = "bulk_checkout";
} elseif (isset($bdlaction_x))
{
$action = "bulk_download";
} elseif (isset($bdeleteaction_x))
{
$action = $owl_lang->del_selected;
}
if ($sess == "0" && $default->anon_ro > 0)
{
header("Location: " . $default->owl_root_url . "/index.php?login=1&failure=4&fileid=$fileid&parent=$parent¤tdb=$default->owl_current_db");
exit;
}
if (!isset($type))
{
$type = "";
}
if (!isset($doctype))
{
$doctype = "1";
}
if ($default->make_file_indexing_user_selectable == 1)
{
$index_file = fIntializeCheckBox($index_file);
}
else
{
$index_file = "1";
}
if ($action == "go_fav")
{
if (!empty($del_favorite_0) and empty($add_favorite_0))
{
$qFavorite = new Owl_DB;
$qFavorite->query("DELETE FROM $default->owl_user_favorites WHERE userid = '$userid' and folder_id = '$favorite_id_0'");
displayBrowsePage($parent);
exit;
}
if (empty($del_favorite_0) and !empty($add_favorite_0))
{
$qFavorite = new Owl_DB;
$qFavorite->query("DELETE FROM $default->owl_user_favorites WHERE userid = '$userid' and folder_id = '$parent'");
$qFavorite->query("INSERT INTO $default->owl_user_favorites VALUES ('$userid','$parent', '$fav_label_0')");
displayBrowsePage($parent);
exit;
}
$parent = $favorite_id_0;
displayBrowsePage($favorite_id_0);
exit;
}
function fSetFileAcl( $file_id )
{
global $default, $userid;
$qSetAcl = "DELETE FROM $default->owl_advanced_acl_table where file_id = '$file_id'";
$sql = new Owl_DB;
$sql->query($qSetAcl);
$qSetAcl = "";
$keys=array_keys($_POST);
$total_fields=count($keys);
$FirstTimeThrough = true;
$bChangeTypeSameId = false;
for($index=0;$index<$total_fields;$index++)
{
$temp_key=$keys[$index];
$temp=$_POST[$temp_key];
list ($type, $acl, $gid_uid) = explode("_", $temp_key);
if ( $type == "gacl" or $type == "acl")
{
if ($iPrevType != $type)
{
$bChangeTypeSameId = true;
}
if (($iPrevUidGid != $gid_uid and $FirstTimeThrough == false) or $bChangeTypeSameId == true)
{
if ($iPrevType == "gacl")
{
$qSetAcl .= ", group_id , file_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$file_id')";
}
if ($iPrevType == "acl")
{
$qSetAcl .= ", user_id , file_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$file_id')";
}
$sql->query($qSetAcl . $qSetAclValues);
$FirstTimeThrough = true;
$bChangeTypeSameId = false;
}
if($FirstTimeThrough)
{
$qSetAcl = "INSERT INTO $default->owl_advanced_acl_table (";
$qSetAclValues = " VALUES ( ";
$FirstTimeThrough = false;
}
else
{
$qSetAcl .= ", ";
$qSetAclValues .= ", ";
}
$qSetAcl .= "$acl ";
$qSetAclValues .= "'1' ";
$iPrevType = $type;
$iPrevUidGid = $gid_uid;
}
}
if ($iPrevType == "gacl")
{
$qSetAcl .= ", group_id , file_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$file_id')";
}
if ($iPrevType == "acl")
{
$qSetAcl .= ", user_id , file_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$file_id')";
}
$sql->query($qSetAcl . $qSetAclValues);
owl_syslog(FILE_ACL, $userid, flid_to_filename($file_id), $parent, "", "FILE", flid_to_filesize($file_id));
}
function fSetFolderAcl( $folder_id , $folder_propagate = 0, $file_propagate = 0)
{
global $default, $userid;
//print("FOLDER='$folder_id' <br />");
$qSetAcl = "DELETE FROM $default->owl_advanced_acl_table where folder_id = '$folder_id'";
$sql = new Owl_DB;
$sql->query($qSetAcl);
$qSetAcl = "";
$keys=array_keys($_POST);
$total_fields=count($keys);
$FirstTimeThrough = true;
$bChangeTypeSameId = false;
for($index=0;$index<$total_fields;$index++)
{
$temp_key=$keys[$index];
$temp=$_POST[$temp_key];
list ($type, $acl, $gid_uid) = explode("_", $temp_key);
if ( $type == "fgacl" or $type == "facl")
{
if ($iPrevType != $type)
{
$bChangeTypeSameId = true;
}
if (($iPrevUidGid != $gid_uid and $FirstTimeThrough == false) or $bChangeTypeSameId == true)
{
if ($iPrevType == "fgacl")
{
$qSetAcl .= ", group_id , folder_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$folder_id')";
}
if ($iPrevType == "facl")
{
$qSetAcl .= ", user_id , folder_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$folder_id')";
}
$sql->query($qSetAcl . $qSetAclValues);
$FirstTimeThrough = true;
$bChangeTypeSameId = false;
}
if($FirstTimeThrough)
{
$qSetAcl = "INSERT INTO $default->owl_advanced_acl_table (";
$qSetAclValues = " VALUES ( ";
$FirstTimeThrough = false;
}
else
{
$qSetAcl .= ", ";
$qSetAclValues .= ", ";
}
$qSetAcl .= "$acl ";
$qSetAclValues .= "'1' ";
$iPrevType = $type;
$iPrevUidGid = $gid_uid;
}
}
if ($iPrevType == "fgacl")
{
$qSetAcl .= ", group_id , folder_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$folder_id')";
}
if ($iPrevType == "facl")
{
$qSetAcl .= ", user_id , folder_id )";
$qSetAclValues .= ", '$iPrevUidGid', '$folder_id')";
}
$sql->query($qSetAcl . $qSetAclValues);
if(fIsAdmin() or $default->user_can_propagate_acl)
{
$qSubFolder = new Owl_DB;
if ($file_propagate == 1)
{
$qSubFolder->query("SELECT id from $default->owl_files_table where parent='$folder_id'");
while($qSubFolder->next_record())
{
fSetFileAcl($qSubFolder->f("id"));
}
}
if($folder_propagate == 1)
{
$qSubFolder->query("SELECT id from $default->owl_folders_table where parent='$folder_id'");
while($qSubFolder->next_record())
{
if (fIsAdmin() or check_auth($qSubFolder->f("id"), "folder_acl", $userid) == 1)
{
fSetFolderAcl($qSubFolder->f("id"), $folder_propagate, $file_propagate);
}
}
}
}
owl_syslog(FOLDER_ACL, $userid, fid_to_name($folder_id), $parent, "", "FILE");
}
if ($action == "folder_acl")
{
if (check_auth($id, "folder_acl", $userid) == 1)
{
fSetFolderAcl($id, $folder_propagate, $file_propagate);
displayBrowsePage($parent);
}
else
{
printError($owl_lang->err_nofoldermod);
}
}
if ($action == "file_acl")
{
if (!is_numeric($id))
{
$aFileIDs = unserialize(stripslashes($id));
foreach ($aFileIDs as $id)
{
if (check_auth($id, "file_acl", $userid) == 1)
{
fSetFileAcl($id);
notify_monitored($id, $type);
notify_monitored_folders ($parent, flid_to_filename($id));
}
else
{
printError($owl_lang->err_nofilemod);
}
}
displayBrowsePage($parent);
}
else
{
if (check_auth($id, "file_acl", $userid) == 1)
{
fSetFileAcl($id);
notify_monitored($id, $type);
notify_monitored_folders ($parent, flid_to_filename($id));
displayBrowsePage($parent);
}
else
{
printError($owl_lang->err_nofilemod);
}
}
}
if ($action == "folder_thumb" and fisAdmin())
{
fGenFolderThumbNails($id);
displayBrowsePage($parent);
}
if ($action == "file_thumb" and fisAdmin())
{
fGenerateThumbNail($id);
displayBrowsePage($parent);
}
if ( $default->document_peer_review == 1)
{
if (($action == "approvedoc" or $action == "docreject") and fCheckIfReviewer($id))
{
$sql_custom = new Owl_DB;
// *****************************
// PEER Review feature END
// *****************************
if ($action == "approvedoc")
{
$sql_custom->query("SELECT * FROM $default->owl_peerreview_table WHERE file_id ='$id' and status <> '1'");
if ($sql_custom->num_rows() > 1)
{
notify_reviewer (owlfilecreator($id), $id, $message, "approved");
}
else
{
if($default->peer_auto_publish[$default->owl_current_db] == "true")
{
notify_reviewer (owlfilecreator($id), $id, $message, "final_approved_auto", $owl_lang->peer_final_approval);
$sql_custom->query("SELECT * FROM $default->owl_files_table WHERE id = '$id'");
$sql_custom->next_record();
notify_users($usergroupid, NEW_FILE, $sql_custom->f("id"));
notify_monitored_folders ($sql_custom->f("parent"), $sql_custom->f("filename"));
$sql_custom->query("UPDATE $default->owl_files_table SET approved = '1' WHERE id = '$id'");
$sql_custom->query("DELETE from $default->owl_peerreview_table where file_id = '" . $id . "'");
owl_syslog(FILE_PUBLISHED, $userid, flid_to_filename($id), owlfileparent($id), "AUTO PUBLISHED", "FILE", flid_to_filesize($id));
}
elseif($default->peer_auto_publish[$default->owl_current_db] == "false")
{
notify_reviewer (owlfilecreator($id), $id, $message, "final_approved", $owl_lang->peer_final_approval);
}
}
$docstatus = "1";
}
else
{
notify_reviewer (owlfilecreator($id), $id, $message, "rejected", $reject_reason);
$docstatus = "2";
}
$result = $sql_custom->query("UPDATE $default->owl_peerreview_table SET status = '$docstatus' WHERE reviewer_id = '$userid' and file_id ='$id'");
// *****************************
// PEER Review feature END
// *****************************
$urlArgs = array();
$urlArgs['sess'] = $sess;
$urlArgs['parent'] = $parent;
$urlArgs['expand'] = $expand;
$urlArgs['order'] = $order;
$urlArgs['sortorder'] = $sortorder;
$urlArgs['curview'] = $curview;
$urlArgs2 = $urlArgs;
$urlArgs2['type'] = "wa";
$sUrl = fGetURL ('showrecords.php', $urlArgs2);
header("Location: " . fOwl_ereg_replace("&","&", $sUrl));
exit;
}
}
if ($action == "set_intial")
{
if (check_auth($parent, "folder_view", $userid) != "1")
{
printError($owl_lang->err_nofolderaccess);
}
else
{
$sql = new Owl_DB;
$sql->query("UPDATE $default->owl_users_table SET firstdir='$parent' WHERE id = '$userid'");
}
}
if ($action == "file_update")
{
if (check_auth($id, "file_update", $userid) == 1)
{
$sql = new Owl_DB;
if ($sign_close == "Cancel")
{
$sql->query("UPDATE $default->owl_files_table set checked_out='0' WHERE id='$id'");
owl_syslog(FILE_UNLOCKED, $userid, flid_to_filename($id), $parent, $owl_lang->log_detail, "FILE", flid_to_filesize($id));
displayBrowsePage($parent);
exit;
}
if ($inline == 1)
{
$new_name = flid_to_filename($id);
$doc_size = strlen($document_content);
}
else
{
if ($default->use_ubr_progress_bar == 1 && $type == "")
{
$userfile['name'] = file_basename($file_name);
$userfile['size'] = $file_size;
$userfile['tmp_name'] = $default->ubr_progress_bar_upload_dir . "/" . $userfile['name'];
}
else if ($default->use_progress_bar == 1)
{
$userfile['name'] = file_basename($file['name'][0]);
$userfile['size'] = $file['size'][0];
$userfile['tmp_name'] = $file['tmp_name'][0];
}
else
{
$userfile = uploadCompat("userfile");
}
fVirusCheck($userfile["tmp_name"], $userfile["name"]);
$new_name = trim(fOwl_ereg_replace("[^$default->list_of_valid_chars_in_file_names]", "", fOwl_ereg_replace("%20|^-", "_", $userfile["name"])));
$doc_size = $userfile['size'];
}
$newpath = $default->owl_FileDir . DIR_SEP . find_path($parent) . DIR_SEP . $new_name;
/**
* Begin Daphne Change - backups of files
* If user requests automatic backups of files
* get current details from db and save file state information
*/
if ($default->owl_version_control == 1)
{
if ($default->owl_use_fs)
{
$sql->query("SELECT * FROM $default->owl_files_table WHERE id='$id'");
}
else
{
// this is guaranteed to get the ID of the most recent revision, just in case we're updating a previous rev.
$sql->query("SELECT distinct b.* FROM $default->owl_files_table a, $default->owl_files_table b WHERE b.id='$id' AND a.name=b.name AND a.parent=b.parent order by major_revision, minor_revision desc");
}
while ($sql->next_record())
{
// save state information
if ($sql->f("checked_out") > 0 and $sql->f("checked_out") <> $userid)
{
printError($owl_lang->err_update_file_lock . " " . uid_to_name($sql->f("checked_out")));
}
$major_revision = $backup_major = $sql->f("major_revision");
$minor_revision = $backup_minor = $sql->f("minor_revision");
$linkedto = $backup_linkedto = $sql->f("linkedto");
if (empty($backup_linkedto))
{
$backup_linkedto = "0"; // unkown
$linkedto = "0"; // unkown
}
$backup_filename = $sql->f("filename");
$backup_name = $sql->f("name");
// Tiian 2004-02-18
// this stuff prevent errors when title contains apostrophes
//$backup_name = ereg_replace("[\\]'", "'", $backup_name);
$backup_name = stripslashes($backup_name);
//$backup_name = fOwl_ereg_replace("'", "\\'" , fOwl_ereg_replace("[<>]", "", $backup_name));
$backup_name = addslashes(fOwl_ereg_replace("[<>]", "", $backup_name));
$backup_size = $sql->f("f_size");
$backup_creatorid = $sql->f("creatorid");
$backup_updatorid = $sql->f("updatorid");
$backup_name_search = $sql->f("name_search");
$backup_filename_search = $sql->f("filename_search");
$backup_description_search = $sql->f("description_search");
$backup_metadata_search = $sql->f("metadata_search");
if (empty($backup_updatorid))
{
$backup_updatorid = "0"; // unkown
}
// $backup_modified = $sql->f("modified");
$backup_smodified = $sql->f("smodified");
//$dCreateDate = date("Y-m-d H:i:s");
$dCreateDate = $sql->now();
$backup_description = $sql->f("description");
// This is a hack to deal with ' in the description field
// on some system the ' is automaticaly changed to \' and that works
// on other system it stays as ' I have no idea why
// the 2 lines bellow should take care of any case.
//$backup_description = ereg_replace("[\\]'", "'", $backup_description);
$backup_description = stripslashes($backup_description);
//$backup_description = fOwl_ereg_replace("'", "\\'" , $backup_description);
$backup_description = addslashes($backup_description);
$backup_name = stripslashes($backup_name);
//$backup_name = fOwl_ereg_replace("'", "\\'" , $backup_name);
$backup_name = addslashes($backup_name);
$backup_metadata = $sql->f("metadata");
$backup_metadata = stripslashes($backup_metadata);
//$backup_metadata = fOwl_ereg_replace("'", "\\'" , fOwl_ereg_replace("[<>]", "", $backup_metadata));
$backup_metadata = addslashes(fOwl_ereg_replace("[<>]", "", $backup_metadata));
$backup_parent = $sql->f("parent");
$backup_security = $sql->f("security");
$backup_groupid = $groupid = $sql->f("groupid");
$new_quota = fCalculateQuota($userfile['size'], $userid, "ADD");
$filename = $sql->f(filename);
$title = $sql->f(name);
$description = $sql->f(description);
// This is a hack to deal with ' in the description field
// on some system the ' is automaticaly changed to \' and that works
// on other system it stays as ' I have no idea why
// the 2 lines bellow should take care of any case.
//$description = ereg_replace("[\\]'", "'", $description);
$description = stripslashes($description);
//$description = fOwl_ereg_replace("'", "\\'" , $description);
$description = addslashes($description);
//$title = ereg_replace("[\\]'", "'", $title);
$title = stripslashes($title);
//$title = fOwl_ereg_replace("'", "\\'" , fOwl_ereg_replace("[<>]", "", $title));
$title = addslashes(fOwl_ereg_replace("[<>]", "", $title));
if ($default->owl_use_fs)
{
if ($default->owl_FileDir . DIR_SEP . find_path($parent) . DIR_SEP . $sql->f(filename) != $newpath)
{
if ($default->allow_different_filename_update == 1)
{
$sNewFileExtension = fFindFileExtension ( $new_name);
$sOrigFileExtension = fFindFileExtension ( $sql->f(filename));
if ($sNewFileExtension == $sOrigFileExtension)
{
$newpath = $default->owl_FileDir . DIR_SEP . find_path($parent) . DIR_SEP . $sql->f(filename);
$new_name = $sql->f(filename);
}
else
{
printError($owl_lang->err_file_extension_update ." Extension / File Type must be the same");
}
}
else
{
printError("$owl_lang->err_file_update");
}
}
}
}
}
/**
* Begin Daphne Change
* copy old version to backup folder
* change version numbers,
* update database entries
* upload new file over the old
* backup filename will be 'name_majorrev-minorrev' e.g. 'testing_1-2.doc'
*/
if ($default->owl_use_fs)
{
if ($default->owl_version_control == 1)
{
if (!(file_exists($newpath) == 1) || $backup_filename != $new_name)
{
printError("$owl_lang->err_file_not_exist");
}
// Get the file extension.
$extension = explode(".", $new_name);
// rename the new, backed up (versioned) filename
// $version_name = $extension[0]."_$major_revision-$minor_revision.$extension[1]";
// BUG FIX BEGIN
// 657896 filenames in backup folder not correct - SOLUTION
// by: Gerald McMillen (mrshadow76)
$extensioncounter = 0;
while ($extension[$extensioncounter + 1] != null)
{
// pre-append a "." separator in the name for each
// subsequent part of the the name of the file.
if ($extensioncounter != 0)
{
$version_name = $version_name . ".";
}
$version_name = $version_name . $extension[$extensioncounter];
$extensioncounter++;
}
if ($extensioncounter != 0)
{
$version_name = $version_name . "_$major_revision-$minor_revision.$extension[$extensioncounter]";
}
else
{
$version_name = $extension[0] . "_$major_revision-$minor_revision";
}
// BUG FIX END
// specify path for new file in the /backup/ file of each directory.
$backuppath = $default->owl_FileDir . DIR_SEP . find_path($parent) . "/$default->version_control_backup_dir_name/$version_name";
// Danilo change
if (!is_dir("$default->owl_FileDir/" . find_path($parent) . "/$default->version_control_backup_dir_name"))
{
mkdir("$default->owl_FileDir/" . find_path($parent) . "/$default->version_control_backup_dir_name", $default->directory_mask);
// End Danilo change
// is there already a backup directory for current dir?
if (is_dir("$default->owl_FileDir/" . find_path($parent) . "/$default->version_control_backup_dir_name"))
{
$sql->query("INSERT INTO $default->owl_folders_table (name, parent, security, groupid, creatorid, description, linkedto) values ('$default->version_control_backup_dir_name', '$parent', '" . fCurFolderSecurity($parent) ."', '" . owlfoldergroup($parent) ."', '" . owlfoldercreator($parent) . "', '', '0')");
$newParent = $sql->insert_id($default->owl_folders_table, 'id');
fSetDefaultFolderAcl($newParent);
fSetInheritedAcl($parent, $newParent, "FOLDER");
}
else
{
printError("$owl_lang->err_backup_folder_create");
}
}
copy($newpath, $backuppath); // copy existing file to backup folder
}
// End Daphne Change
if (!file_exists($newpath) == 1)
{
printError("$owl_lang->err_file_update");
}
if($inline == 1)
{
if ($default->owl_use_fs)
{
$iOldSize = filesize($newpath);
$iCurrentSize = strlen($document_content);
$fp = fopen($newpath, "wb");
fwrite($fp, stripslashes($document_content));
fclose($fp);
}
else
{
$sOldSize = filesize( $default->owl_tmpdir . DIR_SEP . $new_name);
$iCurrentSize = strlen($document_content);
$tmpfile = $default->owl_tmpdir . DIR_SEP . $new_name;
$filedata = addSlashes($document_content);
$fp = fopen($tmpfile, "wb");
fwrite($fp, $document_content);
fclose($fp);
}
$new_current_quota = fCalculateQuota($iOldSize, $backup_creatorid, "DEL");
$new_quota = fCalculateQuota($iCurrentSize, $backup_creatorid, "ADD");
if (fIsQuotaEnabled($backup_creatorid))
{
$sql->query("UPDATE $default->owl_users_table SET quota_current = '$new_quota' WHERE id = '$backup_creatorid'");
}
}
else
{
copy($userfile['tmp_name'], $newpath);
chmod($newpath, $default->file_mask);
unlink($userfile['tmp_name']);
}
if (!file_exists($newpath))
{
if ($default->debug == true)
{
printError("DEBUG: " . $owl_lang->err_upload, $newpath);
}
else
{
printError($owl_lang->err_upload);
}
}
// Begin Daphne Change
if ($default->owl_version_control == 1)
{
if (!file_exists($backuppath))
{
printError("$owl_lang->err_backup_file");
}
// find id of the backup folder you are saving the old file to
$sql->query("SELECT id FROM $default->owl_folders_table WHERE name='$default->version_control_backup_dir_name' AND parent='$parent'");
while ($sql->next_record())
{
$backup_parent = $sql->f("id");
}
}
}
//print("<br/> Major : $major_revision");
//print("<br/> Minor : $minor_revision");
if ($versionchange == 'major_revision')
{
//print("<br /><br />V MAJOR : $versionchange");
// if someone requested a major revision, must
// make the minor revision go back to 0
// $versionchange = "minor_revision='0', major_revision";
// $new_version_num = $major_revision + 1;
$new_major = $major_revision + 1;
$new_minor = 0;
$versionchange = "minor_revision='0', major_revision";
$new_version_num = $major_revision + 1;
}
else
{
//print("<br /><br />V MINOR : $versionchange");
// simply increment minor revision number
$new_version_num = $major_revision;
$new_minor = $minor_revision + 1;
$versionchange = "minor_revision='$new_minor', major_revision";
$new_major = $major_revision;
}
//exit("<br />V: $versionchange = $new_version_num");
// End Daphne Change
$groupid = owlusergroup($userid);
$smodified = $sql->now();
// Begin Daphne Change
$iDocApproved = fIsDocApproved ($reviewers, $newpath);
if ($default->owl_version_control == 1)
{
if ($default->owl_use_fs)
{
// insert entry for backup file
$result = $sql->query("INSERT INTO $default->owl_files_table (name,filename,f_size,creatorid,updatorid,parent,created, smodified,groupid,description,metadata,security,major_revision,minor_revision, doctype, linkedto, approved) values ('" . $sql->make_arg_safe($backup_name) . "','" . $sql->make_arg_safe($version_name) . "','$backup_size','$backup_creatorid','$backup_updatorid','$backup_parent',$dCreateDate,'$backup_smodified','$backup_groupid', '$backup_description','$backup_metadata','$backup_security','$backup_major','$backup_minor', '$doctype', '$backup_linkedto', '1')") or unlink($backuppath);
if (!$result && $default->owl_use_fs) unlink($newpath);
$idbackup = $sql->insert_id($default->owl_files_table, 'id');
$sql->query("UPDATE $default->owl_files_table SET f_size='$doc_size', smodified=$smodified, $versionchange='$new_version_num',description='$newdesc', approved = '$iDocApproved', updatorid='$userid' WHERE id='$id'") or unlink($newpath);
// UPDATE THE VERSION of the linked files as well.
$sql->query("UPDATE $default->owl_files_table SET f_size='$doc_size', smodified=$smodified, $versionchange='$new_version_num',description='$newdesc', updatorid='$userid' WHERE linkedto='$id'") or unlink($newpath);
$sql->query("UPDATE $default->owl_searchidx SET owlfileid='$idbackup' WHERE owlfileid='$id'");
fIndexAFile($backup_filename, $newpath, $id);
fCopyFileAcl($id, $idbackup);
owl_syslog(FILE_UPDATED, $userid, $userfile["name"], $parent, $version_name, "FILE", $userfile['size']);
}
else
{
// BEGIN wes change
// insert entry for current version of file
$compressed = '0';
$userfile = uploadCompat("userfile");
$fsize = filesize($userfile['tmp_name']);
$sql->query("INSERT INTO $default->owl_files_table (name,filename,f_size,creatorid,updatorid,parent, created, smodified,groupid,description,metadata,security,major_revision,minor_revision, doctype, linkedto, approved) VALUES ('$backup_name','" . $userfile['name'] . "','" . $userfile['size'] . "','$backup_creatorid','$userid','$parent',$dCreateDate,$smodified,'$backup_groupid', '$newdesc', '$backup_metadata','$backup_security','$new_major','$new_minor', '$doctype', '$backup_linkedto', '$iDocApproved')");
$fid = $id;
$id = $sql->insert_id($default->owl_files_table, 'id');
$monitorSQL = new Owl_DB;
// Move ACL's for this file
// make them the same as the file Originally updated.
$sql->query("UPDATE $default->owl_advanced_acl_table SET file_id='$id' WHERE file_id = '$fid'");
//
$monitorSQL = new Owl_DB;
$monitorSQL->query("SELECT * FROM $default->owl_monitored_file_table WHERE fid = $fid and userid = '$userid'");
if ($monitorSQL->num_rows() != 0)
{
$monitorSQL->query("SELECT id FROM $default->owl_files_table WHERE name = '$backup_name' and parent = '$parent' and major_revision = '$new_major' and minor_revision = '$new_minor'");
$monitorSQL->next_record();
$newmonitorid = $monitorSQL->f("id");
$monitorSQL->query("UPDATE $default->owl_monitored_file_table SET fid = '$newmonitorid'");
}
// If pdftotext was set and exists
// Create a search index for this text file.
fIndexAFile($userfile['name'], $userfile['tmp_name'], $id);
if ($default->owl_compressed_database && file_exists($default->gzip_path))
{
system(escapeshellarg($default->gzip_path) . " " . escapeshellarg($userfile['tmp_name']));
$fd = fopen($userfile['tmp_name'] . ".gz", 'rb');
$userfile['tmp_name'] = $userfile['tmp_name'] . ".gz";
$fsize = filesize($userfile['tmp_name']);
$compressed = '1';
}
else
{
$fd = fopen($userfile['tmp_name'], 'rb');
}
//$filedata = fread($fd, $fsize);
$filedata = fEncryptFiledata(fread($fd, $fsize));
fclose($fd);
unlink($userfile['tmp_name']);
if ($id !== null && $filedata)
{
$filedatasql = new Owl_DB;
$filedatasql->query("INSERT INTO $default->owl_files_data_table (id, data, compressed) values ('$id', '$filedata', '$compressed')", 'latin1');
}
owl_syslog(FILE_UPDATED, $userid, $userfile["name"], $parent, $backup_name, "FILE", $userfile['size']);
}
}
else // versioning not included in the DB update
{
$filename = $userfile['name'];
// BEGIN Bozz Change
if (getfilepolicy($id) == 5 || getfilepolicy($id) == 6)
{
$sql->query("UPDATE $default->owl_files_table SET f_size='" . $userfile['size'] . "',smodified=$smodified, updatorid='$userid', approved='$iDocApproved' WHERE id='$id'") or unlink($newpath);
}
else
{
$sql->query("UPDATE $default->owl_files_table SET f_size='" . $userfile['size'] . "',updatorid='$userid', smodified=$smodified, approved='$iDocApproved' WHERE id='$id'") or unlink($newpath);
}
if ($default->owl_use_fs == false)
{
fDeleteFileIndexID($id);
fIndexAFile($userfile['name'], $userfile['tmp_name'], $id);
$fsize = filesize($userfile['tmp_name']);
if ($default->owl_compressed_database && file_exists($default->gzip_path))
{
system(escapeshellarg($default->gzip_path) . " " . escapeshellarg($userfile['tmp_name']));
$fd = fopen($userfile['tmp_name'] . ".gz", 'rb');
$userfile['tmp_name'] = $userfile['tmp_name'] . ".gz";
$fsize = filesize($userfile['tmp_name']);
$compressed = '1';
}
else
{
$fd = fopen($userfile['tmp_name'], 'rb');
}
//$filedata = fread($fd, $fsize);
$filedata = fEncryptFiledata(fread($fd, $fsize));
fclose($fd);
unlink($userfile['tmp_name']);
if ($filedata)
{
$filedatasql = new Owl_DB;
$filedatasql->query("UPDATE $default->owl_files_data_table set data = '$filedata' where id ='$id'", 'latin1');
}
}
owl_syslog(FILE_UPDATED, $userid, $userfile["name"], $parent, $backup_name, "FILE", $userfile['size']);
}
// End Daphne Change
if (fIsQuotaEnabled($userid))
{
$sql->query("UPDATE $default->owl_users_table SET quota_current = '$new_quota' WHERE id = '$userid'");
}
//
// Yes Yes Yes, I know you may get 3 notification
// for the same file, I should probably check
// if a notification was already sent by
// the previous notification, but I wait and see
// I'll probably get complaints and feed back
// and I'll fix this later if need be.
//
// *****************************