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
|
<?php
// $Id$
function _proposal_pending_solution()
{
/* get pending proposals to be approved */
$pending_rows = array();
$pending_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 AND solution_status = 0 ORDER BY id DESC");
while ($pending_data = db_fetch_object($pending_q)) {
$pending_rows[$pending_data->id] = array(date('d-m-Y', $pending_data->creation_date), l($pending_data->name_title . ' ' . $pending_data->name, 'user/' . $pending_data->uid), $pending_data->department, $pending_data->university, $pending_data->lab_title, l('Upload Solution', '/lab_migration/manage_proposal/solution/' . $pending_data->id));
}
/* check if there are any pending proposals */
if (!$pending_rows) {
drupal_set_message(t('There are no pending proposals to be solved.'), 'status');
return '';
}
$pending_header = array('Date of Submission', 'Name of the Proposer', 'Department/Branch', 'University/Institute', 'Title of the Lab', 'Action');
$output = theme_table($pending_header, $pending_rows);
return $output;
}
/******************************************************************************/
/************************** PROPOSAL SOLUTION FORM ****************************/
/******************************************************************************/
function proposal_solution_form($form_state)
{
global $user;
$dl_root_path = 'sites/default/files/lab_migration/';
/* get current proposal */
$proposal_id = arg(3);
$result = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
if (!($row = db_fetch_object($result))) {
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('lab_migration/manage_proposal/pending_proposal');
return;
}
if ($row->approval_status != 1) {
drupal_set_message(t('Selected Proposal has not been approved yet.'), 'error');
drupal_goto('lab_migration/manage_proposal/pending_proposal');
return;
}
if ($row->solution_status != 0) {
drupal_set_message(t('Selected Proposal has already been solved.'), 'error');
drupal_goto('lab_migration/manage_proposal/pending_proposal');
return;
}
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['name_title'] = array(
'#type' => 'item',
'#value' => $row->name_title,
'#title' => t('Title'),
);
$form['name'] = array(
'#type' => 'item',
'#value' => l($row->name, 'user/' . $row->uid),
'#title' => t('Name of the Proposer'),
);
$form['email'] = array(
'#type' => 'item',
'#value' => user_load($row->uid)->mail,
'#title' => t('Email'),
);
$form['contact_ph'] = array(
'#type' => 'item',
'#value' => $row->contact_ph,
'#title' => t('Contact Phone No.'),
);
$form['department'] = array(
'#type' => 'item',
'#value' => $row->department,
'#title' => t('Department/Branch'),
);
$form['university'] = array(
'#type' => 'item',
'#value' => $row->university,
'#title' => t('University/Institute'),
);
$form['lab_title'] = array(
'#type' => 'item',
'#value' => $row->lab_title,
'#title' => t('Title of the Lab'),
);
$form['problem_topic'] = array(
'#type' => 'item',
'#value' => $row->problem_topic,
'#title' => t('Topic of the Problem'),
);
$problem_file_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filetype = 'P'", $row->id);
$problem_file_data = db_fetch_object($problem_file_q);
if ($problem_file_data) {
$form['problem_file'] = array(
'#type' => 'item',
'#value' => l($problem_file_data->filename, $dl_root_path . $problem_file_data->filepath),
'#title' => t('Problem statement'),
);
}
$sup_file_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filetype = 'S'", $row->id);
$sup_file_data = db_fetch_object($sup_file_q);
if ($sup_file_data) {
$form['supplementary_file'] = array(
'#type' => 'item',
'#value' => l($sup_file_data->filename, $dl_root_path . $sup_file_data->filepath),
'#title' => t('Supplementary file'),
);
}
$approver_user_data = user_load($row->approver_uid );
$form['approval_details'] = array(
'#type' => 'item',
'#value' => 'By : ' . l($approver_user_data->name, 'user/' . $row->approver_uid) . '<br />'
. 'On : ' . date('d-m-Y', $row->approval_date),
);
$form['solution_file'] = array(
'#type' => 'file',
'#title' => t('Upload solution statement'),
'#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
t('Allowed file extensions : ') . variable_get('lab_migration_uploads_extensions', ''),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
$form['cancel'] = array(
'#type' => 'markup',
'#value' => l(t('Cancel'), 'lab_migration/manage_proposal/pending_solution'),
);
return $form;
}
function proposal_solution_form_validate($form, &$form_state)
{
$proposal_id = arg(3);
if ( ! ($_FILES['files']['name']['solution_file'])) {
form_set_error('problem_file', t('Solution statement file is required.'));
} else {
$allowed_extensions_str = variable_get('lab_migration_uploads_extensions', '');
$allowed_extensions = explode(',' , $allowed_extensions_str);
$temp_extension = end(explode('.', strtolower($_FILES['files']['name']['solution_file'])));
if (!in_array($temp_extension, $allowed_extensions))
form_set_error('solution_file', t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
if ($_FILES['files']['size']['solution_file'] <= 0)
form_set_error('solution_file', t('File size cannot be zero.'));
/* check if valid file name */
if (!lab_migration_check_valid_filename($_FILES['files']['name']['solution_file']))
form_set_error('solution_file', t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
/* if file already exists */
$file_exists_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filename = '%s'", $proposal_id, $_FILES['files']['name']['solution_file']);
if (db_fetch_object($file_exists_q))
form_set_error('solution_file', t('File with the same name already exists. Please rename the solution file and try again.'));
}
return;
}
function proposal_solution_form_submit($form, &$form_state)
{
global $user;
$root_path = lab_migration_path();
/* get current proposal */
$proposal_id = (int)arg(3);
$result = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
if (!($row = db_fetch_object($result))) {
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('lab_migration/manage_proposal');
return;
}
if ($row->approval_status != 1) {
drupal_set_message(t('Selected Proposal has not been approved yet.'), 'error');
drupal_goto('lab_migration/manage_proposal/pending_solution');
return;
}
if ($row->solution_status != 0) {
drupal_set_message(t('Selected Proposal has already been solved.'), 'error');
drupal_goto('lab_migration/manage_proposal/pending_solution');
return;
}
/************** uploading file *******************/
/* creating directories */
$dest_path = $proposal_id . '/';
if (!is_dir($root_path . $dest_path))
mkdir($root_path . $dest_path);
if (file_exists($root_path . $dest_path . $_FILES['files']['name']['solution_file']))
{
drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['solution_file'])), 'error');
return;
}
/* uploading file */
$filename = $_FILES['files']['name']['solution_file'];
if (move_uploaded_file($_FILES['files']['tmp_name']['solution_file'], $root_path . $dest_path . $filename))
{
/* for uploaded files making an entry in the database */
db_query("INSERT INTO {lab_migration_files} (link_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$proposal_id,
$filename,
$dest_path . $filename,
$_FILES['files']['type']['solution_file'],
$_FILES['files']['size']['solution_file'],
'A',
time()
);
db_query("UPDATE {lab_migration_proposal} SET solution_status = 1, solver_uid = %d, solution_date = %d WHERE id = %d", $user->uid, time(), $proposal_id);
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $filename, 'error');
}
drupal_goto('lab_migration/manage_proposal/pending_solution');
}
|