summaryrefslogtreecommitdiff
path: root/full_download.inc
blob: eafd6c7dacd396a10e6fccf3ae6cbd7115406332 (plain)
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
<?php
// $Id$
function circuit_simulation_download_full_project()
{
	global $user;
	$id = arg(3);
	$root_path = circuit_simulation_path();
	$query = db_select('esim_circuit_simulation_proposal');
	$query->fields('esim_circuit_simulation_proposal');
	$query->condition('id', $id);
	$circuit_simulation_q = $query->execute();
	$circuit_simulation_data = $circuit_simulation_q->fetchObject();
	$CIRCUITSIMULATION_PATH = $circuit_simulation_data->directory_name . '/';
	/* zip filename */
	$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
	/* creating zip archive on the server */
	$zip = new ZipArchive();
	$zip->open($zip_filename, ZipArchive::CREATE);
	$query = db_select('esim_circuit_simulation_proposal');
	$query->fields('esim_circuit_simulation_proposal');
	$query->condition('id', $id);
	$circuit_simulation_udc_q = $query->execute();
	while ($circuit_simulation_udc_row = $circuit_simulation_udc_q->fetchObject()) {
		if ($circuit_simulation_udc_row->samplefilepath != 'NULL') {
			$REFERENCE_PATH = 'Reference_file/';
			$str = substr($circuit_simulation_udc_row->samplefilepath,strrpos($circuit_simulation_udc_row->samplefilepath, '/'));
		$resource_file =ltrim($str, '/');
			$zip->addFile($root_path . $CIRCUITSIMULATION_PATH . $resource_file , $REFERENCE_PATH . str_replace(' ', '_', basename($resource_file)));
		} //$CIRCUITSIMULATION_udc_row->user_defined_compound_filepath || $CIRCUITSIMULATION_udc_row->user_defined_compound_filepath != 'NULL'
	} //$CIRCUITSIMULATION_udc_row = $CIRCUITSIMULATION_udc_q->fetchObject()
	$query = db_select('esim_circuit_simulation_proposal');
	$query->fields('esim_circuit_simulation_proposal');
	$query->condition('id', $id);
	//$circuit_simulation_f_q = $query->execute();
	/*while ($circuit_simulation_data) {
		$str = substr($circuit_simulation_data->samplefilepath,strrpos($circuit_simulation_data->samplefilepath, '/'));
		$resource_file =ltrim($str, '/');
		$zip->addFile($root_path . $CIRCUITSIMULATION_PATH . $resource_file);
		//var_dump($root_path . $CIRCUITSIMULATION_PATH . $resource_file);die;
	} //$CIRCUITSIMULATION_f_row = $CIRCUITSIMULATION_f_q->fetchObject()
	*/$zip_file_count = $zip->numFiles;
	$zip->close();
	if ($zip_file_count > 0) {
		if ($user->uid) {
			/* download zip file */
			header('Content-Type: application/zip');
			header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $circuit_simulation_data->project_title) . '.zip"');
			header('Content-Length: ' . filesize($zip_filename));
			ob_end_flush();
			ob_clean();
			flush();
			readfile($zip_filename);
			unlink($zip_filename);
		} //$user->uid
		else {
			header('Content-Type: application/zip');
			header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $circuit_simulation_data->project_title) . '.zip"');
			header('Content-Length: ' . filesize($zip_filename));
			header("Content-Transfer-Encoding: binary");
			header('Expires: 0');
			header('Pragma: no-cache');
			ob_end_flush();
			ob_clean();
			flush();
			readfile($zip_filename);
			unlink($zip_filename);
		}
	} //$zip_file_count > 0
	else {
		drupal_set_message("There are no circuit simulation project in this proposal to download", 'error');
		drupal_goto('circuit-simulation-project/full-download/project');
	}
}
function circuit_simulation_download_completed_project()
{
		global $user;
	$id = arg(3);
	$root_path = circuit_simulation_path();
	$query = db_select('esim_circuit_simulation_proposal');
	$query->fields('esim_circuit_simulation_proposal');
	$query->condition('id', $id);
	$circuit_simulation_q = $query->execute();
	$circuit_simulation_data = $circuit_simulation_q->fetchObject();
	$CIRCUITSIMULATION_PATH = $circuit_simulation_data->directory_name . '/';
	/* zip filename */
	$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
	/* creating zip archive on the server */
	$zip = new ZipArchive();
	$zip->open($zip_filename, ZipArchive::CREATE);
	$query = db_select('esim_circuit_simulation_proposal');
	$query->fields('esim_circuit_simulation_proposal');
	$query->condition('id', $id);
	$circuit_simulation_udc_q = $query->execute();
	while ($circuit_simulation_udc_row = $circuit_simulation_udc_q->fetchObject()) {
		if ($circuit_simulation_udc_row->samplefilepath != 'NULL') {
			$REFERENCE_PATH = 'Reference_file/';
			$str = substr($circuit_simulation_udc_row->samplefilepath,strrpos($circuit_simulation_udc_row->samplefilepath, '/'));
		$resource_file =ltrim($str, '/');
			$zip->addFile($root_path . $CIRCUITSIMULATION_PATH . $resource_file , $REFERENCE_PATH . str_replace(' ', '_', basename($resource_file)));
		} //$CIRCUITSIMULATION_udc_row->user_defined_compound_filepath || $CIRCUITSIMULATION_udc_row->user_defined_compound_filepath != 'NULL'
	} //$CIRCUITSIMULATION_udc_row = $CIRCUITSIMULATION_udc_q->fetchObject()
	$query = db_select('esim_circuit_simulation_proposal');
	$query->fields('esim_circuit_simulation_proposal');
	$query->condition('id', $id);
	//$circuit_simulation_f_q = $query->execute();
	/*while ($circuit_simulation_data) {
		$str = substr($circuit_simulation_data->samplefilepath,strrpos($circuit_simulation_data->samplefilepath, '/'));
		$resource_file =ltrim($str, '/');
		$zip->addFile($root_path . $CIRCUITSIMULATION_PATH . $resource_file);
		//var_dump($root_path . $CIRCUITSIMULATION_PATH . $resource_file);die;
	} //$CIRCUITSIMULATION_f_row = $CIRCUITSIMULATION_f_q->fetchObject()
	*/$zip_file_count = $zip->numFiles;
	$zip->close();
	if ($zip_file_count > 0) {
		if ($user->uid) {
			/* download zip file */
			header('Content-Type: application/zip');
			header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $circuit_simulation_data->project_title) . '.zip"');
			header('Content-Length: ' . filesize($zip_filename));
			ob_end_flush();
			ob_clean();
			flush();
			readfile($zip_filename);
			unlink($zip_filename);
		} //$user->uid
		else {
			header('Content-Type: application/zip');
			header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $circuit_simulation_data->project_title) . '.zip"');
			header('Content-Length: ' . filesize($zip_filename));
			header("Content-Transfer-Encoding: binary");
			header('Expires: 0');
			header('Pragma: no-cache');
			ob_end_flush();
			ob_clean();
			flush();
			readfile($zip_filename);
			unlink($zip_filename);
		}
	} //$zip_file_count > 0
	else {
		drupal_set_message("There are circuit simulation project in this proposal to download", 'error');
		drupal_goto('circuit-simulation-project/full-download/project');
	}
}