| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
include_once( '../../header.php' );
|
2 |
include_once( '../../header.php' );
|
| 3 |
include_once( './functions.php' );
|
3 |
include_once( './functions.php' );
|
| 4 |
|
4 |
|
| - |
|
5 |
|
| - |
|
6 |
$expectedValues = array( 'file_id','device_id','site_id','client_id','file_mime_type_id','added_date', 'removed_date', 'name', 'description', 'name_on_disk' );
|
| - |
|
7 |
foreach ( $expectedValues as $field )
|
| - |
|
8 |
$oldValues[$field] = '';
|
| - |
|
9 |
$oldValues['added_date'] = date('Y-m-d', time() );
|
| - |
|
10 |
// next three lines are useless code. Picks up referrer even if we choose the menu option
|
| - |
|
11 |
// maybe add a parameter to the menu option to work around it, later.
|
| 5 |
$result = '';
|
12 |
$returnTo = '';
|
| - |
|
13 |
if ( isset( $_REQUEST['referer'] ) ) // we came from somewhere else, just to edit one record
|
| - |
|
14 |
$returnTo = $_REQUEST['referer'];
|
| - |
|
15 |
$mode = 'Edit';
|
| - |
|
16 |
$result = array();
|
| 6 |
$debug = '';
|
17 |
$debug = array();
|
| - |
|
18 |
logIt( "Beginning a run\n========================\n" );
|
| 7 |
if ( isset( $_REQUEST['uploadfile'] ) ) {
|
19 |
if ( isset( $_REQUEST['uploadfile'] ) ) {
|
| 8 |
// clean up the input first
|
20 |
// clean up the input first
|
| 9 |
$client_id = cleanInput( $_REQUEST['client_id'] );
|
21 |
foreach ( $expectedValues as $field )
|
| 10 |
$site_id = cleanInput( $_REQUEST['site_id'] );
|
22 |
$fields[$field] = cleanInput( $_REQUEST[$field], $field == 'name' ? $_FILES['fileToUpload']['name'] : '' );
|
| - |
|
23 |
|
| 11 |
$device_id = cleanInput( $_REQUEST['device_id'] );
|
24 |
$mode = $fields['file_id'] ? 'Replace' : 'Add';
|
| 12 |
$name = cleanInput( $_REQUEST['name'], $_FILES['fileToUpload']['name'] );
|
25 |
logIt( "Mode set to $mode" );
|
| 13 |
$description = cleanInput( $_REQUEST['description'] );
|
26 |
if ( isset( $_FILES['fileToUpload']['error'] ) ) {
|
| 14 |
$mime_type_id = $_REQUEST['mime_type'];
|
27 |
$result = getFileUploadError( $_FILES['fileToUpload']['error'] );
|
| 15 |
// mime_type_id can be passed in, calculated from the 'type' of $_FILES, or looked up by extension
|
28 |
logIt( 'File Upload Status:<br>' . print_r( getFileUploadError( $_FILES['fileToUpload']['error'] ), true ) );
|
| 16 |
if ( $mime_type_id == 0 ) { // we need to calculate the mime type (auto mode)
|
29 |
if ( $_FILES['fileToUpload']['error'] == UPLOAD_ERR_NO_FILE ) {
|
| 17 |
// see if $_FILES has the info
|
- |
|
| 18 |
$mime_type_id = check_mime_type( $_FILES['fileToUpload']['type'] );
|
30 |
$result = array( 'valid' => true, 'message' => "Entering Edit Mode" );
|
| 19 |
if ( $mime_type_id === null ) { // no, so see if we can figure it out from the file name
|
31 |
logIt( "Changing to Edit mode since they didn't upload a file" );
|
| 20 |
$mime_type_id = check_mime_type( pathinfo($_FILES['fileToUpload']['name'], PATHINFO_EXTENSION) );
|
32 |
$mode = 'Edit';
|
| 21 |
}
|
33 |
}
|
| 22 |
}
|
34 |
}
|
| - |
|
35 |
|
| 23 |
$debug = "client_id =[$client_id]<br />
|
36 |
if ( $result['valid'] && $mode == 'Replace' ) {
|
| 24 |
site_id =[$site_id]<br />
|
37 |
logIt( "Replace mode, removing record $fields[file_id]" );
|
| 25 |
device_id =[$device_id]<br />
|
38 |
// we are overwriting a record, so just mark the previous one removed
|
| 26 |
name =[$name]<br />
|
39 |
doSQL( "update file set removed_date = now() where file_id = $fields[file_id]" );
|
| 27 |
mime_type_id=[$mime_type_id]<br />
|
40 |
$fields['file_id'] = '';
|
| 28 |
description =[$description]<br />";
|
41 |
$mode = 'Add';
|
| 29 |
/*
|
42 |
}
|
| - |
|
43 |
|
| 30 |
* this documentation will use the following example
|
44 |
if ( $result['valid'] && $mode == 'Add' ) { // we are adding a file, so we upload it
|
| 31 |
* A file, joe.csv, is uploaded and attached to the client
|
45 |
logIt( "Actually uploading file" );
|
| 32 |
* Walder IP Law. makeFileName discovers it to be file number
|
46 |
// file_mime_type_id can be passed in, calculated from the 'type' of $_FILES, or looked up by extension
|
| 33 |
* 123456 (based on an internal counter)
|
47 |
if ( $fields['file_mime_type_id'] == 0 ) { // we need to calculate the mime type (auto mode)
|
| 34 |
* All comments below show what is returned
|
48 |
// see if $_FILES has the info
|
| 35 |
*/
|
- |
|
| 36 |
$result = makeFileName(
|
- |
|
| 37 |
$_FILES['fileToUpload']['name'],
|
49 |
$fields['file_mime_type_id'] = check_mime_type( $_FILES['fileToUpload']['type'] );
|
| 38 |
$device_id,
|
50 |
if ( $fields['file_mime_type_id'] === null ) { // no, so see if we can figure it out from the file name
|
| 39 |
$client_id,
|
51 |
$fields['file_mime_type_id'] = check_mime_type( pathinfo($_FILES['fileToUpload']['name'], PATHINFO_EXTENSION) );
|
| 40 |
$site_id
|
52 |
}
|
| 41 |
);
|
53 |
}
|
| 42 |
// at this point, we have 12/34/123456-c-Walder IP Law.csv
|
54 |
logIt( 'Field List: ' . print_r( $fields, true ) );
|
| 43 |
if ( $result['valid'] ) {
|
55 |
/*
|
| 44 |
$nameOnDisk = $result['filename'];
|
56 |
* this documentation will use the following example
|
| 45 |
$saveTo = getAbsolutePath( $nameOnDisk );
|
57 |
* A file, joe.csv, is uploaded and attached to the client
|
| 46 |
// $saveT now has document root, etc... prepended, so
|
58 |
* Walder IP Law. makeFileName discovers it to be file number
|
| 47 |
// /var/www/computer_asset_management/modules/files/file_storage/12/34/123456-c-Walder IP Law.csv
|
- |
|
| 48 |
if ( makePath( $saveTo ) ) {
|
59 |
* 123456 (based on an internal counter)
|
| 49 |
$result = "Path Made - $saveTo";
|
60 |
* All comments below show what is returned
|
| 50 |
if ( ( move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $saveTo ) ) ) {
|
61 |
*/
|
| 51 |
$result = addfile(
|
62 |
$result = makeFileName(
|
| 52 |
$nameOnDisk,
|
63 |
$_FILES['fileToUpload']['name'],
|
| 53 |
$device_id,
|
64 |
$fields['device_id'],
|
| 54 |
$client_id,
|
65 |
$fields['client_id'],
|
| 55 |
$site_id,
|
66 |
$fields['site_id']
|
| 56 |
isset( $_REQUEST['mime_type'] ) ? $_REQUEST['mime_type'] : $_FILES["fileToUpload"]['type'],
|
- |
|
| 57 |
$name,
|
67 |
);
|
| 58 |
$description
|
68 |
// at this point, we have 12/34/123456-c-Walder IP Law.csv
|
| 59 |
);
|
69 |
if ( $result['valid'] ) {
|
| 60 |
$result = $result === null ? "Could not add file<br />$nameOnDisk<br />to database" : 'Success';
|
70 |
logIt( 'preparing to upload file, result = ' . print_r( $result, true ) );
|
| 61 |
} else {
|
71 |
$fields['name_on_disk'] = $result['filename'];
|
| 62 |
$result = "Failed to upload to disk<br />$saveTo";
|
72 |
$result = uploadFile( $_FILES["fileToUpload"]["tmp_name"], $fields['name_on_disk'] );
|
| 63 |
} // if move_uploaded_file .. else
|
73 |
logIt( "After upload, result is " . print_r( $result, true ) );
|
| 64 |
} else {
|
74 |
} else {
|
| 65 |
$result = "failed to make path<br />$saveTo";
|
75 |
$result = array( 'valid' => false, 'message' => "failed to make path<br />$saveTo" );
|
| 66 |
}
|
76 |
}
|
| 67 |
} else {
|
77 |
}
|
| - |
|
78 |
logIt( "Just before adding file, result =\n" . print_r( $result, true ) );
|
| - |
|
79 |
if ( $result['valid'] ) {
|
| 68 |
$result = $result['message'];
|
80 |
$result = addfile( $fields );
|
| - |
|
81 |
}
|
| - |
|
82 |
/*
|
| - |
|
83 |
if ( $returnTo )
|
| - |
|
84 |
header( "Location: $returnTo" );
|
| - |
|
85 |
*/
|
| - |
|
86 |
} elseif ( $_REQUEST['file_id'] ) { // if isset uploadfile
|
| - |
|
87 |
$oldValues = queryDatabaseExtended( "select * from file where file_id = $_REQUEST[file_id]" );
|
| - |
|
88 |
if ( $oldValues ) {
|
| - |
|
89 |
$oldValues = $oldValues['data'][0];
|
| - |
|
90 |
switch ( $oldValues['owner_type'] ) {
|
| - |
|
91 |
case 'd' : $oldValues['device_id'] = $oldValues['owner_id'];
|
| - |
|
92 |
break;
|
| - |
|
93 |
case 'c' : $oldValues['client_id'] = $oldValues['owner_id'];
|
| 69 |
} // if nameOnDisk .. else
|
94 |
break;
|
| - |
|
95 |
case 's' : $oldValues['site_id'] = $oldValues['owner_id'];
|
| 70 |
} // if isset uploadfile
|
96 |
break;
|
| - |
|
97 |
}
|
| - |
|
98 |
}
|
| - |
|
99 |
}
|
| 71 |
?>
|
100 |
?>
|
| 72 |
<?xml version="1.0" encoding="utf-8"?>
|
101 |
<?xml version="1.0" encoding="utf-8"?>
|
| 73 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
102 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 74 |
<html xmlns="http://www.w3.org/1999/xhtml">
|
103 |
<html xmlns="http://www.w3.org/1999/xhtml">
|
| 75 |
<head>
|
104 |
<head>
|
| Line 78... |
Line 107... |
| 78 |
</head>
|
107 |
</head>
|
| 79 |
<body>
|
108 |
<body>
|
| 80 |
<?php include_once('../../menu.php'); ?>
|
109 |
<?php include_once('../../menu.php'); ?>
|
| 81 |
<div id="content">
|
110 |
<div id="content">
|
| 82 |
<?php
|
111 |
<?php
|
| 83 |
if ( isset( $result ) ) print "<h3>$result</h3>";
|
112 |
if ( $result ) print '<h3>' . $result['valid'] ? "Success" : "Error" . $result['message'] . '</h3>';
|
| 84 |
//if ( isset( $debug ) ) print "<h3>$debug</h3>";
|
113 |
//if ( isset( $debug ) ) print "<h3>" . implode( '<br />', $debug ) . "</h3>";
|
| 85 |
?>
|
114 |
?>
|
| - |
|
115 |
<h4>Upload a File</h4>
|
| - |
|
116 |
<p>Max size: <?php print maxUploadFileSize(); ?></p>
|
| 86 |
<p>Choose only <b>one</b> of device, site or client to add the file to</p>
|
117 |
<p>Choose only <b>one</b> of device, site or client to add the file to</p>
|
| 87 |
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
|
118 |
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
|
| - |
|
119 |
<input type='hidden' name='referer' value='<?php print $_SERVER['HTTP_REFERER']; ?>' />
|
| 88 |
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
|
120 |
<input type='hidden' name='file_id' value='<?php print $oldValues['file_id']; ?>' />
|
| 89 |
<table>
|
121 |
<table>
|
| 90 |
<tr>
|
122 |
<tr>
|
| 91 |
<td>
|
123 |
<td>
|
| 92 |
Attach To Device
|
124 |
Attach To Device
|
| 93 |
</td>
|
125 |
</td>
|
| 94 |
<td>
|
126 |
<td>
|
| 95 |
<select name='device_id' >
|
127 |
<select name='device_id' >
|
| 96 |
<option value='0'>------------</option>
|
128 |
<option value='0'>------------</option>
|
| 97 |
<?php print queryToSelect('select device_id, Device from view_current_client_systems order by Device' ); ?>
|
129 |
<?php print queryToSelect('select device_id, Device from view_current_client_systems order by Device', $oldValues['device_id'] ); ?>
|
| 98 |
</select>
|
130 |
</select>
|
| 99 |
</td>
|
131 |
</td>
|
| 100 |
</tr>
|
132 |
</tr>
|
| 101 |
<tr>
|
133 |
<tr>
|
| 102 |
<td>
|
134 |
<td>
|
| 103 |
Attach To Site
|
135 |
Attach To Site
|
| 104 |
</td>
|
136 |
</td>
|
| 105 |
<td>
|
137 |
<td>
|
| 106 |
<select name='site_id' >
|
138 |
<select name='site_id' >
|
| 107 |
<option value='0'>------------</option>
|
139 |
<option value='0'>------------</option>
|
| 108 |
<?php print queryToSelect('select site_id, name from view_current_client_site order by name' ); ?>
|
140 |
<?php print queryToSelect('select site_id, name from view_current_client_site order by name', $oldValues['site_id'] ); ?>
|
| 109 |
</select>
|
141 |
</select>
|
| 110 |
</td>
|
142 |
</td>
|
| 111 |
</tr>
|
143 |
</tr>
|
| 112 |
<tr>
|
144 |
<tr>
|
| 113 |
<td>
|
145 |
<td>
|
| 114 |
Attach To Client
|
146 |
Attach To Client
|
| 115 |
</td>
|
147 |
</td>
|
| 116 |
<td>
|
148 |
<td>
|
| 117 |
<select name='client_id' >
|
149 |
<select name='client_id' >
|
| 118 |
<option value='0'>------------</option>
|
150 |
<option value='0'>------------</option>
|
| 119 |
<?php print queryToSelect('select client_id, name from view_current_client order by name' ); ?>
|
151 |
<?php print queryToSelect('select client_id, name from view_current_client order by name', $oldValues['client_id'] ); ?>
|
| 120 |
</select>
|
152 |
</select>
|
| 121 |
</td>
|
153 |
</td>
|
| 122 |
</tr>
|
154 |
</tr>
|
| 123 |
<tr>
|
155 |
<tr>
|
| 124 |
<td>
|
156 |
<td>
|
| 125 |
Mime Type
|
157 |
Mime Type
|
| 126 |
</td>
|
158 |
</td>
|
| 127 |
<td>
|
159 |
<td>
|
| 128 |
<select name='mime_type_id' >
|
160 |
<select name='file_mime_type_id' >
|
| 129 |
<option value='0'>Autodetect</option>
|
161 |
<option value='0'>Autodetect</option>
|
| 130 |
<?php print queryToSelect("select file_mime_type_id, concat( extension, ' (', mime_type, ')') from file_mime_type order by extension" ); ?>
|
162 |
<?php print queryToSelect("select file_mime_type_id, concat( extension, ' (', mime_type, ')') from file_mime_type order by extension", $oldValues['file_mime_type_id'] ); ?>
|
| 131 |
</select>
|
163 |
</select>
|
| 132 |
</td>
|
164 |
</td>
|
| 133 |
</tr>
|
165 |
</tr>
|
| 134 |
<tr>
|
166 |
<tr>
|
| 135 |
<td>
|
167 |
<td>
|
| - |
|
168 |
File Date
|
| - |
|
169 |
</td>
|
| - |
|
170 |
<td>
|
| - |
|
171 |
<input type='text' name='added_date' width='20' value='<?php print $oldValues['added_date']; ?>' >
|
| - |
|
172 |
</td>
|
| - |
|
173 |
</tr>
|
| - |
|
174 |
<tr>
|
| - |
|
175 |
<td>
|
| - |
|
176 |
Removed Date
|
| - |
|
177 |
</td>
|
| - |
|
178 |
<td>
|
| - |
|
179 |
<input type='text' name='removed_date' width='20' value='<?php print $oldValues['removed_date']; ?>' >
|
| - |
|
180 |
</td>
|
| - |
|
181 |
</tr>
|
| - |
|
182 |
<tr>
|
| - |
|
183 |
<td>
|
| 136 |
file Name
|
184 |
File Name
|
| 137 |
</td>
|
185 |
</td>
|
| 138 |
<td>
|
186 |
<td>
|
| 139 |
<input type="text" name="name" size="30" maxlength="64" />
|
187 |
<input type="text" name="name" size="30" maxlength="64" value='<?php print $oldValues['name']; ?>' />
|
| 140 |
</td>
|
188 |
</td>
|
| 141 |
</tr>
|
189 |
</tr>
|
| 142 |
<tr>
|
190 |
<tr>
|
| 143 |
<td valign='top'>
|
191 |
<td valign='top'>
|
| 144 |
Description
|
192 |
Description
|
| 145 |
</td>
|
193 |
</td>
|
| 146 |
<td>
|
194 |
<td>
|
| 147 |
<textarea name="description" cols='50' rows='5'></textarea>
|
195 |
<textarea name="description" cols='50' rows='5'><?php print $oldValues['description']; ?></textarea>
|
| 148 |
</td>
|
196 |
</td>
|
| 149 |
</tr>
|
197 |
</tr>
|
| 150 |
<tr>
|
198 |
<tr>
|
| 151 |
<td>
|
199 |
<td>
|
| 152 |
Choose File
|
200 |
Choose File
|