summaryrefslogtreecommitdiff
path: root/general_deletion.inc
diff options
context:
space:
mode:
Diffstat (limited to 'general_deletion.inc')
-rw-r--r--general_deletion.inc124
1 files changed, 124 insertions, 0 deletions
diff --git a/general_deletion.inc b/general_deletion.inc
index dc06a7a..b7b2661 100644
--- a/general_deletion.inc
+++ b/general_deletion.inc
@@ -90,3 +90,127 @@ function delete_solution($solution_id)
return $status;
}
+function delete_experiment($experiment_id)
+{
+ $status = TRUE;
+ $root_path = lab_migration_path();
+
+ $experiment_q = db_query("SELECT * FROM {lab_migration_chapter} WHERE id = %d", $experiment_id);
+ $experiment_data = db_fetch_object($experiment_q);
+ if (!$experiment_data)
+ {
+ drupal_set_message('Invalid experiment.', 'error');
+ return FALSE;
+ }
+
+ /* deleting solutions */
+ $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d", $experiment_id);
+ while ($solution_data = db_fetch_object($solution_q))
+ {
+ if (!delete_solution($solution_data->id))
+ $status = FALSE;
+ }
+
+ if ($status)
+ {
+ $dir_path = $root_path . $experiment_data->proposal_id . '/EXP' . $experiment_data->number;
+
+ if (is_dir($dir_path))
+ {
+ $res = rmdir($dir_path);
+ if (!$res)
+ {
+ drupal_set_message(t('Error deleting experiment folder !folder', array('!folder' => $dir_path)), 'error');
+
+ /* sending email to admins */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting experiment folder";
+ $param['standard']['body'] = "Error deleting folder " . $dir_path;
+ if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ return FALSE;
+ } else {
+ return TRUE;
+ }
+ } else {
+ drupal_set_message(t('Cannot delete experiment folder. !folder does not exists.', array('!folder' => $dir_path)), 'error');
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
+function delete_lab($lab_id)
+{
+ $status = TRUE;
+ $root_path = lab_migration_path();
+
+ $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $lab_id);
+ $proposal_data = db_fetch_object($proposal_q);
+ if (!$proposal_data)
+ {
+ drupal_set_message('Invalid Lab.', 'error');
+ return FALSE;
+ }
+
+ /* delete experiments */
+ $experiment_q = db_query("SELECT * FROM {lab_migration_chapter} WHERE proposal_id = %d", $proposal_data->id);
+ while ($experiment_data = db_fetch_object($experiment_q))
+ {
+ if (!delete_experiment($experiment_data->id))
+ {
+ $status = FALSE;
+ }
+ }
+ return $status;
+}
+
+
+function delete_file($file_id)
+{
+ $root_path = lab_migration_path();
+
+ $file_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE id = %d LIMIT 1", $file_id);
+ $file_data = db_fetch_object($file_q);
+ if (!$file_data)
+ {
+ drupal_set_message('Invalid file specified.', 'error');
+ return FALSE;
+ }
+
+ if (!file_exists($root_path . $file_data->filepath))
+ {
+ drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $file_data->filepath)), 'error');
+ return FALSE;
+ }
+
+ /* removing solution file */
+ if (!unlink($root_path . $file_data->filepath))
+ {
+ drupal_set_message(t('Error deleting !file', array('!file' => $file_data->filepath)), 'error');
+
+ /* sending email to admins */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting file";
+ $param['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ file id : " . $file_id . "
+ file path : " . $file_data->filepath;
+ if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ return FALSE;
+ } else {
+ /* deleting example files database entries */
+ db_query("DELETE FROM {lab_migration_solution_files} WHERE id = %d", $file_id);
+ return TRUE;
+ }
+}
+
+function del_lab_pdf($lab_id)
+{
+ $root_path = lab_migration_path();
+ $dir_path = $root_path . "latex/";
+ $pdf_filename = "lab_" . $lab_id . ".pdf";
+ if (file_exists($dir_path . $pdf_filename))
+ unlink($dir_path . $pdf_filename);
+}
+