summaryrefslogtreecommitdiff
path: root/general_deletion.inc
blob: 3622d7a0903f511d22d0d98ce88ecc14ec77d349 (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
<?php
/******************************************************************************/
/****************************** DELETION FUNCTIONS ****************************/
/******************************************************************************/
function dwsim_flowsheet_delete_abstract_file($abstract_id)
{
	$status = TRUE;
	$root_path = dwsim_flowsheet_path();
	$abstract_q = db_query("SELECT * from dwsim_flowsheet_proposal dfp
LEFT JOIN dwsim_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('dwsim_flowsheet_submitted_abstracts_file');
	$query->fields('dwsim_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);

	} 
	//$abstract_f_data = $abstract_f_q->fetchObject()
	//!$delete_project_folder
	/*if ($status)
	{
		$dir_path_udc = $root_path . $abstract_f_data->directory_name . '/user_defined_compound';
		if (is_dir($dir_path_udc))
		{
			unlink($root_path . $abstract_f_data->directory_name . '/' . $abstract_f_data->user_defined_compound_filepath);
			$res = rmdir($dir_path_udc);
			if (!$res)
			{
				drupal_set_message(t('Error in deleting user defiend folder !folder', array(
					'!folder' => $abstract_f_data->directory_name
				)), 'error');
				/* sending email to admins */
		/*		$email_to = variable_get('dwsim_flowsheet_emails', '');
				$from = variable_get('dwsim_flowsheet_from_email', '');
				$bcc = "";
				$cc = variable_get('dwsim_flowsheet_cc_emails', '');
				$params['standard']['subject'] = "[ERROR] Error deleting experiment folder";
				$params['standard']['body'] = "Error deleting folder " . $dir_path;
				$params['standard']['headers'] = array(
					'From' => $from,
					'MIME-Version' => '1.0',
					'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
					'Content-Transfer-Encoding' => '8Bit',
					'X-Mailer' => 'Drupal',
					'Cc' => $cc,
					'Bcc' => $bcc
				);
				if (!drupal_mail('dwsim_flowsheet', 'standard', $email_to, language_default(), $params, $from, TRUE))
					drupal_set_message('Error sending email message.', 'error');
				return FALSE;
			} //!$res
			else
			{
				return TRUE;
			}
		} //is_dir($dir_path_udc)
	} */ //$status
	return True;
}
function dwsim_flowsheet_abstract_delete_project($proposal_id)
{
	$status = TRUE;
	$root_path = dwsim_flowsheet_path();
	//$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $lab_id);
	$query = db_select('dwsim_flowsheet_proposal');
	$query->fields('dwsim_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('dwsim_flowsheet_submitted_abstracts');
	$query->fields('dwsim_flowsheet_submitted_abstracts');
	$query->condition('proposal_id', $proposal_data->id);
	$abstract_q = $query->execute();
	while ($abstract_data = $abstract_q->fetchObject())
	{
		if (!dwsim_flowsheet_delete_abstract_file($abstract_data->id))
		{
			$status = FALSE;
		} //!dwsim_flowsheet_delete_abstract_file($abstract_data->id)
	} //$abstract_data = $abstract_q->fetchObject()
	$dir_path_udc = $root_path . $proposal_data->directory_name . '/user_defined_compound';
	if (is_dir($dir_path_udc))
	{
		unlink($root_path . $proposal_data->directory_name . '/' . $proposal_data->user_defined_compound_filepath);
		$res = rmdir($dir_path_udc);
	} //is_dir($dir_path_udc)
	$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('dwsim_flowsheet_proposal')->condition('id', $proposal_data->id)->execute();
	db_delete('dwsim_flowsheet_submitted_abstracts')->condition('proposal_id', $proposal_data->id)->execute();
	db_delete('dwsim_flowsheet_submitted_abstracts_file')->condition('id', $abstract_f_data->id)->execute();
	return $status;
}