diff options
author | Sashi20 | 2021-08-31 12:08:08 +0530 |
---|---|---|
committer | Sashi20 | 2021-08-31 12:08:08 +0530 |
commit | 5ae18f6c52f81de8d2017eed4f5ae60e0026c57f (patch) | |
tree | 221e1ceed14c0a09e9ad0ab189053a352c2cf9eb | |
parent | bce18b6c1950b107e445106b99d1e9315e93866a (diff) | |
download | cfd_lab_migration-5ae18f6c52f81de8d2017eed4f5ae60e0026c57f.tar.gz cfd_lab_migration-5ae18f6c52f81de8d2017eed4f5ae60e0026c57f.tar.bz2 cfd_lab_migration-5ae18f6c52f81de8d2017eed4f5ae60e0026c57f.zip |
Update solution provider fields in proposal form, fix lab deletion in bulk manage
-rwxr-xr-x | bulk_approval.inc | 11 | ||||
-rwxr-xr-x | general_deletion.inc | 390 | ||||
-rwxr-xr-x | proposal.inc | 16 |
3 files changed, 185 insertions, 232 deletions
diff --git a/bulk_approval.inc b/bulk_approval.inc index 39ac9c2..5a94634 100755 --- a/bulk_approval.inc +++ b/bulk_approval.inc @@ -391,9 +391,9 @@ function lab_migration_bulk_approval_form_submit($form, &$form_state) $root_path = lab_migration_path(); if ($form_state['clicked_button']['#value'] == 'Submit') { - if ($form_state['values']['lab']) + /*if ($form_state['values']['lab']) lab_migration_del_lab_pdf($form_state['values']['lab']); - if (user_access('lab migration bulk manage code')) + */if (user_access('lab migration bulk manage code')) { $query = db_select('lab_migration_proposal'); $query->fields('lab_migration_proposal'); @@ -574,11 +574,12 @@ FOSSEE,IIT Bombay', array( if (lab_migration_delete_lab($form_state['values']['lab'])) { drupal_set_message(t('Dis-Approved and Deleted Entire Lab solutions.'), 'status'); - $query = db_select('lab_migration_experiment'); - $query->fields('lab_migration_experiment'); - $query->condition('proposal_id', $form_state['values']['lab']); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $form_state['values']['lab']); $experiment_q = $query->execute()->fetchObject(); $dir_path = $root_path . $experiment_q->directory_name; + //var_dump($dir_path);die; if (is_dir($dir_path)) { $res = rmdir($dir_path); diff --git a/general_deletion.inc b/general_deletion.inc index 2125732..fcddeea 100755 --- a/general_deletion.inc +++ b/general_deletion.inc @@ -1,13 +1,13 @@ <?php + /******************************************************************************/ /****************************** DELETION FUNCTIONS ****************************/ /******************************************************************************/ function lab_migration_delete_solution($solution_id) - { +{ global $user; $root_path = lab_migration_path(); $status = TRUE; - //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d", $solution_id); $query = db_select('lab_migration_solution'); $query->fields('lab_migration_solution'); $query->condition('id', $solution_id); @@ -18,284 +18,224 @@ function lab_migration_delete_solution($solution_id) drupal_set_message(t('Invalid solution.'), 'error'); return FALSE; } - //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id); - $experiment_q = db_query("SELECT lme.*, lmp.id, lmp.directory_name FROM lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lmp.id = lme.proposal_id AND lme.id = :experiment_id",array(':experiment_id' => $solution_data->experiment_id)); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); $experiment_data = $experiment_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); if (!$experiment_data) - { + { drupal_set_message(t('Invalid experiment.'), 'error'); return FALSE; - } - /* deleting solution files */ - //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_id); - $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_id)); - /*$query = db_select('lab_migration_solution_files'); + } + /* deleting solution files */ + $query = db_select('lab_migration_solution_files'); $query->fields('lab_migration_solution_files'); $query->condition('solution_id', $solution_id); - $solution_files_q = $query->execute();*/ + $solution_files_q = $query->execute(); while ($solution_files_data = $solution_files_q->fetchObject()) - { - if (!file_exists($root_path .$solution_files_data->directory_name. '/'. $solution_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file. File does not exists.', array( - '!file' => $solution_files_data->directory_name. '/' . $solution_files_data->filepath - )), 'error'); - continue; - } - /* removing solution file */ - if (!unlink($root_path . $solution_files_data->directory_name. '/'. $solution_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file', array( - '!file' => $solution_files_data->directory_name. '/' . $solution_files_data->filepath - )), 'error'); - /* sending email to admins */ + { + $ex_path = $proposal_data->directory_name . '/' . $solution_files_data->filepath; + $dir_path = $root_path . $ex_path; + if (!file_exists($dir_path)) + { + $status = FALSE; + drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $dir_path)), 'error'); + continue; + } + /* removing solution file */ + if (!unlink($dir_path)) + { + $status = FALSE; + drupal_set_message(t('Error deleting !file', array('!file' => $dir_path)), 'error'); + + /* sending email to admins */ $email_to = variable_get('lab_migration_emails', ''); $from = variable_get('lab_migration_from_email', ''); - $bcc = ""; - $cc = variable_get('lab_migration_cc_emails', ''); + $bcc=""; + $cc=variable_get('lab_migration_cc_emails', ''); $param['standard']['subject'] = "[ERROR] Error deleting example file"; $param['standard']['body'] = "Error deleting solution files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - solution id : " . $solution_id . " - file id : " . $solution_files_data->id . " - file path : " . $solution_files_data->directory_name. '/'. $solution_files_data->filepath . " - PDF path : " . $PdfStatus; - $param['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 - ); + solution id : " . $solution_id . " + file id : " . $solution_files_data->id . " + file path : " . $solution_files_data->filepath." + PDF path : " . $PdfStatus; + $param['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('lab_migration', 'standard', $email_to, language_default(), $param, $from, TRUE)) - drupal_set_message('Error sending email message.', 'error'); - } - else - { - /* deleting example files database entries */ - db_delete('lab_migration_solution_files')->condition('id', $solution_files_data->id)->execute(); - } - } + drupal_set_message('Error sending email message.', 'error'); + } + else { + /* deleting example files database entries */ + db_delete('lab_migration_solution_files')->condition('id', $solution_files_data->id)->execute(); + } + } + if (!$status) + return FALSE; + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution.'), 'error'); return FALSE; - /* removing code folder */ - $ex_path = $experiment_data->directory_name . '/EXP' . $experiment_data->number . '/CODE' . $solution_data->code_number; - $dir_path = $root_path . $ex_path; + } + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + $dir_path = $root_path . $proposal_data->directory_name . '/EXP' . $experiment_data->number . '/CODE' . $solution_data->code_number; if (is_dir($dir_path)) - { + { if (!rmdir($dir_path)) - { - drupal_set_message(t('Error deleting folder !folder', array( - '!folder' => $dir_path - )), 'error'); - /* sending email to admins */ + { + drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error'); + + /* sending email to admins */ $email_to = variable_get('lab_migration_emails', ''); $from = variable_get('lab_migration_from_email', ''); - $bcc = ""; - $cc = variable_get('lab_migration_cc_emails', ''); + $bcc=""; + $cc=variable_get('lab_migration_cc_emails', ''); + + $param['standard']['subject'] = "[ERROR] Error deleting folder"; $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - $param['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 - ); + $param['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('lab_migration', 'standard', $email_to, language_default(), $param, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } - } - else - { - drupal_set_message(t('Cannot delete solution folder. !folder does not exists.', array( - '!folder' => $dir_path - )), 'error'); + return FALSE; + } + } + else + { + drupal_set_message(t('Cannot delete solution folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); return FALSE; - } - /* deleting solution dependency and solution database entries */ + } + + /* deleting solution dependency and solution database entries */ db_delete('lab_migration_solution_dependency')->condition('solution_id', $solution_id)->execute(); db_delete('lab_migration_solution')->condition('id', $solution_id)->execute(); return $status; - } +} + function lab_migration_delete_experiment($experiment_id) - { +{ $status = TRUE; $root_path = lab_migration_path(); - //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $experiment_id); $query = db_select('lab_migration_experiment'); $query->fields('lab_migration_experiment'); $query->condition('id', $experiment_id); $experiment_q = $query->execute(); $experiment_data = $experiment_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); 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); + } + /* deleting solutions */ $query = db_select('lab_migration_solution'); $query->fields('lab_migration_solution'); $query->condition('experiment_id', $experiment_id); $solution_q = $query->execute(); $delete_exp_folder = FALSE; while ($solution_data = $solution_q->fetchObject()) - { + { $delete_exp_folder = TRUE; if (!lab_migration_delete_solution($solution_data->id)) - $status = FALSE; - } + $status = FALSE; + } if (!$delete_exp_folder) - { + { return TRUE; - } + } if ($status) - { - $dir_path = $root_path . $experiment_data->directory_name . '/EXP' . $experiment_data->number; + { + $dir_path = $root_path . $proposal_data->directory_name . '/EXP' . $experiment_data->number; if (is_dir($dir_path)) + { + $res = rmdir($dir_path); + if (!$res) { - $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', ''); - $from = variable_get('lab_migration_from_email', ''); - $bcc = ""; - $cc = variable_get('lab_migration_cc_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting experiment folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path; - $param['standard']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 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', ''); + $from = variable_get('lab_migration_from_email', ''); + $bcc=""; + $cc=variable_get('lab_migration_cc_emails', ''); + $param['standard']['subject'] = "[ERROR] Error deleting experiment folder"; + $param['standard']['body'] = "Error deleting folder " . $dir_path; + $param['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('lab_migration', 'standard', $email_to, language_default(), $param, $from, 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'); + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param,$from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); return FALSE; - } - } - return FALSE; - } -function lab_migration_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); - $query = db_select('lab_migration_proposal'); - $query->fields('lab_migration_proposal'); - $query->condition('id', $lab_id); - $proposal_q = $query->execute(); - $proposal_data = $proposal_q->fetchObject(); - if (!$proposal_data) - { - drupal_set_message('Invalid Lab.', 'error'); - return FALSE; - } - /* delete experiments */ - //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_data->id); - $query = db_select('lab_migration_experiment'); - $query->fields('lab_migration_experiment'); - $query->condition('proposal_id', $proposal_data->id); - $experiment_q = $query->execute(); - while ($experiment_data = $experiment_q->fetchObject()) - { - if (!lab_migration_delete_experiment($experiment_data->id)) + } + else { - $status = FALSE; + return TRUE; } - } - return $status; - } -function lab_migration_del_lab_pdf($lab_id) + } + else { + drupal_set_message(t('Cannot delete experiment folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); + return FALSE; + } + } + return FALSE; +} + +function lab_migration_delete_lab($lab_id) +{ + $status = TRUE; + $root_path = lab_migration_path(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $lab_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) { - $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); + drupal_set_message('Invalid Lab.', 'error'); + return FALSE; } -function lab_migration_delete_dependency($dependency_id) + /* delete experiments */ + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_data->id); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) { - global $user; - $root_path = lab_migration_path(); - $status = TRUE; - //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_id); - $query = db_select('lab_migration_dependency_files'); - $query->fields('lab_migration_dependency_files'); - $query->condition('id', $dependency_id); - $dependency_files_q = $query->execute(); - $dependency_files_data = $dependency_files_q->fetchObject(); - if (!$dependency_files_data) - { - drupal_set_message(t('Invalid dependency.'), 'error'); - return FALSE; - } - if (!file_exists($root_path . $dependency_files_data->filepath)) - { - drupal_set_message(t('Error deleting !file. File does not exists.', array( - '!file' => $dependency_files_data->filepath - )), 'error'); - return FALSE; - } - /* removing dependency file */ - if (!unlink($root_path . $dependency_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file', array( - '!file' => $dependency_files_data->filepath - )), 'error'); - /* sending email to admins */ - $email_to = variable_get('lab_migration_emails', ''); - $from = variable_get('lab_migration_from_email', ''); - $bcc = ""; - $cc = variable_get('lab_migration_cc_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting dependency file"; - $param['standard']['body'] = "Error deleting dependency files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - dependency id : " . $dependency_id . " - file id : " . $dependency_files_data->id . " - file path : " . $dependency_files_data->filepath; - $param['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('lab_migration', 'standard', $email_to, language_default(), $param, $from, TRUE)) - drupal_set_message('Error sending email message.', 'error'); - } - else - { - /* deleting dependency files database entries */ - db_delete('lab_migration_dependency_files')->condition('id', $dependency_id)->execute(); - } - return $status; + if (!lab_migration_delete_experiment($experiment_data->id)) + { + $status = FALSE; + } } + return $status; +} diff --git a/proposal.inc b/proposal.inc index bd35d39..720d1a7 100755 --- a/proposal.inc +++ b/proposal.inc @@ -404,6 +404,10 @@ function lab_migration_proposal_form_submit($form, &$form_state) $solution_provider_contact_ph = ''; $solution_provider_department = ''; $solution_provider_university = ''; + $solution_provider_city = ''; + $solution_provider_country = ''; + $solution_provider_state = ''; + $solution_provider_pincode = ''; if ($form_state['values']['solution_provider_uid'] == "1") { $solution_provider_uid = $user->uid; @@ -413,6 +417,10 @@ function lab_migration_proposal_form_submit($form, &$form_state) $solution_provider_contact_ph = $form_state['values']['contact_ph']; $solution_provider_department = $form_state['values']['department']; $solution_provider_university = $form_state['values']['university']; + $solution_provider_city = $form_state['values']['city']; + $solution_provider_country = $form_state['values']['country']; + $solution_provider_state = $form_state['values']['all_state']; + $solution_provider_pincode = $form_state['values']['pincode']; } else { @@ -434,11 +442,11 @@ function lab_migration_proposal_form_submit($form, &$form_state) $university = $v['university']; $directory_name = _lm_dir_name($lab_title, $proposar_name, $university); $result = "INSERT INTO {lab_migration_proposal} - (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, country, version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, directory_name) VALUES + (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, country, version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, solution_provider_city, solution_provider_country, solution_provider_state, solution_provider_pincode, directory_name) VALUES (:uid, :approver_uid, :name_title, :name, :contact_ph, :department, :university, :city, :pincode, :state, :country, :version, :lab_title, :approval_status, :solution_status, :solution_provider_uid, :solution_display, :creation_date, :approval_date, :solution_date, :solution_provider_name_title, :solution_provider_name, - :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :directory_name)"; + :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :solution_provider_city, :solution_provider_country, :solution_provider_state, :solution_provider_pincode, :directory_name)"; $args = array( ":uid" => $user->uid, ":approver_uid" => 0, @@ -465,6 +473,10 @@ function lab_migration_proposal_form_submit($form, &$form_state) ":solution_provider_contact_ph" => $solution_provider_contact_ph, ":solution_provider_department" => $solution_provider_department, ":solution_provider_university" => $solution_provider_university, + ":solution_provider_city" => $solution_provider_city, + ":solution_provider_country" => $solution_provider_country, + ":solution_provider_state" => $solution_provider_state, + ":solution_provider_pincode" => $solution_provider_pincode, ":directory_name" => $directory_name ); $proposal_id = db_query($result, $args, array( |