-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_file_aed.php
More file actions
156 lines (138 loc) · 3.83 KB
/
Copy pathdo_file_aed.php
File metadata and controls
156 lines (138 loc) · 3.83 KB
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
<?php /* FILES $Id: do_file_aed.php,v 1.8 2004/03/10 08:46:21 kiryl Exp $ */
require_once("modules/mngdocument/files.class.php");
$file_id = intval( dPgetParam( $_POST, 'file_id', 0 ) );
$del = intval( dPgetParam( $_POST, 'del', 0 ) );
$padre = intval( dPgetParam( $_POST, 'padre', 0 ) );
$descripcion = dPgetParam( $_POST, 'descripcion', '' );
$dirname = dPgetParam( $_POST, 'dirname', '' );
$accion = dPgetParam( $_POST, 'accion', '' );
$actual = dPgetParam( $_POST, 'actual', '' );
$delall = dPgetParam( $_POST, 'delall', '' );
$obj = new CFile();
$obj->_tbl="SGD";
$obj->_tbl_key="SGD_id";
$log = new CFileLog ();
$log->_tbl="SGD_Logs";
$log->_tbl_key="SGD_Log_id";
if (!$obj->bind( $_POST )) {
$AppUI->setMsg( $obj->getError(), UI_MSG_ERROR );
$AppUI->redirect();
}
// prepare (and translate) the module name ready for the suffix
$AppUI->setMsg( 'File' );
// delete the file
if ($del) {
$obj->load( $file_id );
if (($msg = $obj->delete())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
}
set_time_limit( 600 );
ignore_user_abort( 1 );
$log->SGD_Logs_user_id = $AppUI->user_id;
$log->SGD_Logs_date = Date("d/m/Y H:i");
$log->SGD_Logs_action = $accion;
switch ($accion)
{
case "newdocument":
$upload = null;
if (isset( $_FILES['formfile'] ))
{
$upload = $_FILES['formfile'];
if ($upload['size'] < 1)
{
if (!$file_id)
{
$AppUI->setMsg( 'Upload file size is zero. Process aborted.', UI_MSG_ERROR );
$AppUI->redirect();
}
}
else
{
// store file with a unique name
$obj->SGD_name = $upload['name'];
$obj->SGD_type = 0;
$obj->SGD_date= db_unix2dateTime( time() );
$obj->SGD_parent = $padre;
$obj->SGD_description = $descripcion;
$res = $obj->moveTemp( $upload );
if (!$res)
{
$AppUI->setMsg( 'File could not be written', UI_MSG_ERROR );
$AppUI->redirect();
}
}
}
break;
case "newdirectory":
if (Trim($dirname)=="")
{
$AppUI->setMsg( "Debe de introducir un nombre para el directorio a crear.", UI_MSG_ERROR );
$AppUI->redirect();
}
$obj->SGD_name = $dirname;
$obj->SGD_type = 1;
$obj->SGD_date= db_unix2dateTime( time() );
$obj->SGD_parent = $padre;
$obj->SGD_description = $descripcion;
break;
case "deldirectory":
$sql="select SGD_id,SGD_type,SGD_name from SGD where SGD_parent=$actual";
$resultado=db_exec($sql);
if ($delall<>1 and db_num_rows($resultado)>0)
$AppUI->setMsg( "El directorio contiene ficheros y/o subdirectorios. Imposible eliminar.", UI_MSG_ERROR );
else
BorrarDirectorio($actual,$log);
$AppUI->redirect();
break;
case "deldocument":
if ($delall==1)
{
$sql="select SGD_name from SGD where SGD_id=$actual";
$resultado=db_exec($sql);
$row=db_fetch_row($resultado);
$obj->SGD_name=$row[0];
$obj->SGD_id=$actual;
$obj->deletefile();
$log->SGD_Logs_document_name=$row[0];
if (($msg = $log->store()))
$AppUI->setMsg( $msg, UI_MSG_ERROR );
}
$AppUI->redirect();
break;
}
function BorrarDirectorio($actual,$log)
{
$obj = new CFile();
$obj->_tbl="SGD";
$obj->_tbl_key="codigo";
$sql="select SGD_id,SGD_type,SGD_name from SGD where SGD_parent=$actual";
$resultado=db_exec($sql);
while ($row=db_fetch_row($resultado))
BorrarDirectorio($row[0],$log);
$obj->SGD_id=$actual;
$sql="select SGD_type,SGD_name from SGD where SGD_id=$actual";
$resultado=db_exec($sql);
$row=db_fetch_row($resultado);
$log->SGD_Logs_document_name=$row[1];
if ($row[0]==0)
{
$obj->SGD_name=$row[1];
$obj->deletefile();
}
else
$obj->deletedirectory();
if (($msg = $log->store()))
$AppUI->setMsg( $msg, UI_MSG_ERROR );
}
if (($msg = $obj->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$obj->load($obj->file_id);
$AppUI->setMsg( $file_id ? 'updated' : 'added', UI_MSG_OK, true );
$log->SGD_Logs_document_name = $obj->SGD_name;
$log->store();
}
$AppUI->redirect();
?>