summaryrefslogtreecommitdiff
path: root/general_deletion.inc
blob: 5982156d456c1fe4b17543af90256744b408ff8b (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
<?php
/******************************************************************************/
/****************************** DELETION FUNCTIONS ****************************/
/******************************************************************************/
function om_flowsheet_delete_abstract_file($abstract_id)
{
	$status = TRUE;
	$root_path = om_flowsheet_path();
	$abstract_q = db_query("SELECT * from om_flowsheet_proposal dfp
LEFT JOIN om_flowsheet_submitted_abstracts dfsa ON dfp.id = dfsa.proposal_id
WHERE dfsa.id = :abstract_id", array(
		":abstract_id" => $abstract_id
	));
	$abstract_data = $abstract_q->fetchObject();
	if (!$abstract_data)
	{
		drupal_set_message('Invalid flowsheet project abstract.', 'error');
		return FALSE;
	} //!$abstract_data
	/* deleting solutions */
	$query = db_select('om_flowsheet_submitted_abstracts_file');
	$query->fields('om_flowsheet_submitted_abstracts_file');
	$query->condition('submitted_abstract_id', $abstract_id);
	$abstract_f_q = $query->execute();
	
	while ($abstract_f_data = $abstract_f_q->fetchObject())
	{
		unlink($root_path . $abstract_data->directory_name . '/' . $abstract_f_data->filepath);
		db_delete('om_flowsheet_submitted_abstracts_file')->condition('id', $abstract_f_data->id)->execute();
	} 
	

	return True;
}
function om_flowsheet_abstract_delete_project($proposal_id)
{
	$status = TRUE;
	$root_path = om_flowsheet_path();
	//$proposal_q = db_query("SELECT * FROM {om_flowsheet_proposal} WHERE id = %d", $lab_id);
	$query = db_select('om_flowsheet_proposal');
	$query->fields('om_flowsheet_proposal');
	$query->condition('id', $proposal_id);
	$proposal_q = $query->execute();
	$proposal_data = $proposal_q->fetchObject();
	if (!$proposal_data)
	{
		drupal_set_message('Invalid Flowsheeting Project.', 'error');
		return FALSE;
	} //!$proposal_data
	$query = db_select('om_flowsheet_submitted_abstracts');
	$query->fields('om_flowsheet_submitted_abstracts');
	$query->condition('proposal_id', $proposal_data->id);
	$abstract_q = $query->execute();
	while ($abstract_data = $abstract_q->fetchObject())
	{
		if (!om_flowsheet_delete_abstract_file($abstract_data->id))
		{
			$status = FALSE;
		} //!om_flowsheet_delete_abstract_file($abstract_data->id)
	} //$abstract_data = $abstract_q->fetchObject()
	
	$dir_main_path = $root_path . $proposal_data->directory_name;
	//var_dump($dir_main_path);die;
	if (is_dir($dir_main_path))
	{
		$res_main = rmdir($dir_main_path);
	} //is_dir($dir_main_path)
	
	db_delete('om_flowsheet_submitted_abstracts')->condition('proposal_id', $proposal_data->id)->execute();
	db_delete('om_flowsheet_proposal')->condition('id', $proposal_data->id)->execute();
	return $status;
}