'Power System Simulation Proposal Form', 'description' => 'Power System Simulation Proposal Form', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_proposal_form' ), 'access arguments' => array( 'om pssp create proposal' ), 'type' => MENU_NORMAL_ITEM, 'file' => 'proposal.inc' ); $items['powersystems/pssp/manage-proposal'] = array( 'title' => 'Manage Power System Simulation Proposals', 'description' => 'Manage Power System Simulation Proposals', 'page callback' => 'om_pssp_proposal_pending', 'access callback' => 'user_access', 'access arguments' => array( 'om pssp manage proposal' ), 'file' => 'manage_proposal.inc' ); $items['powersystems/pssp/manage-proposal/pending'] = array( 'title' => 'Pending Proposals', 'description' => 'Pending om pssp Proposals Queue', 'page callback' => 'om_pssp_proposal_pending', 'access callback' => 'user_access', 'access arguments' => array( 'om pssp manage proposal' ), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 1, 'file' => 'manage_proposal.inc' ); $items['powersystems/pssp/manage-proposal/all'] = array( 'title' => 'All Proposals', 'description' => 'All Proposals', 'page callback' => 'om_pssp_proposal_all', 'access callback' => 'user_access', 'access arguments' => array( 'om pssp manage proposal' ), 'type' => MENU_LOCAL_TASK, 'weight' => 4, 'file' => 'manage_proposal.inc' ); $items['powersystems/pssp/manage-proposal/approve'] = array( 'title' => 'Approve Proposal', 'description' => 'Approve Proposal', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_proposal_approval_form' ), 'access arguments' => array( 'om pssp manage proposal' ), 'type' => MENU_CALLBACK, 'file' => 'manage_proposal.inc' ); $items['powersystems/pssp/manage-proposal/edit'] = array( 'title' => 'Edit Proposal', 'description' => 'Edit Proposal', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_proposal_edit_form' ), 'access arguments' => array( 'om pssp manage proposal' ), 'type' => MENU_CALLBACK, 'file' => 'manage_proposal.inc' ); $items['powersystems/pssp/manage-proposal/status'] = array( 'title' => 'Proposal Status', 'description' => 'Proposal Status', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_proposal_status_form' ), 'access arguments' => array( 'om pssp approve proposal' ), 'type' => MENU_CALLBACK, 'file' => 'manage_proposal.inc' ); /*$items['powersystems/pssp/show-proposal'] = array( 'title' => 'om pssp Solution Proposal', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_solution_proposal_form' ), 'access arguments' => array( 'om pssp propose solution' ), 'type' => MENU_CALLBACK, 'file' => 'solution_proposal.inc' );*/ /* CODE REVIEW */ /*$items['powersystems/pssp/code-approval'] = array( 'title' => 'LM Manage Code Approval', 'description' => 'Manage Code Approval', 'page callback' => 'om_pssp_code_approval', 'access arguments' => array( 'om pssp approve code' ), 'type' => MENU_NORMAL_ITEM, 'file' => 'code_approval.inc' ); $items['powersystems/pssp/abstract-approval/approve'] = array( 'title' => 'Code Approval', 'description' => 'Code Approval', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_abstract_approval_form' ), 'access arguments' => array( 'om pssp approve code' ), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 1, 'file' => 'code_approval.inc' );*/ $items['powersystems/pssp/abstract-approval/bulk'] = array( 'title' => 'Bulk Manage', 'description' => 'Bulk Mangage', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_abstract_bulk_approval_form' ), 'access arguments' => array( 'om pssp bulk manage abstract' ), 'type' => MENU_LOCAL_TASK, 'weight' => 2, 'file' => 'abstract_bulk_approval.inc' ); /* CODE UPLOAD */ $items['powersystems/pssp/abstract-code'] = array( 'title' => 'Abstract and Power System Simulation Submission', 'description' => 'Abstract Submission', 'page callback' => 'om_pssp_abstract', 'access callback' => 'user_access', 'access arguments' => array( 'om pssp upload code' ), 'file' => 'upload_code.inc' ); $items['powersystems/pssp/abstract-code/upload'] = array( 'title' => 'Abstract and Power System Simulation Submission', 'description' => 'Abstract Submission', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_upload_abstract_code_form' ), 'access arguments' => array( 'om pssp upload code' ), 'type' => MENU_LOCAL_TASK, 'file' => 'upload_code.inc', 'weight' => 2 ); /* CODE DOWNLOADS */ $items['powersystems/pssp/download/resource-file'] = array( 'title' => 'Download resource file', 'description' => 'Download resource file', 'page callback' => 'om_pssp_download_upload_file', 'access arguments' => array( 'om pssp download code' ), 'type' => MENU_CALLBACK, 'file' => 'download.inc' ); $items['powersystems/pssp/download/abstract-file'] = array( 'title' => 'Download abstract file', 'description' => 'Download abstract file', 'page callback' => 'om_pssp_project_files', 'access arguments' => array( 'om pssp download code' ), 'type' => MENU_CALLBACK, 'file' => 'download.inc' ); $items['powersystems/pssp/download/file'] = array( 'title' => 'Code Download', 'description' => 'Code Download', 'page callback' => 'om_pssp_download_solution_file', 'access arguments' => array( 'om pssp download code' ), 'type' => MENU_CALLBACK, 'file' => 'download.inc' ); $items['powersystems/pssp/full-download/project'] = array( 'title' => 'Code Download', 'description' => 'Code Download', 'page callback' => 'om_pssp_download_full_project', 'access arguments' => array( 'om pssp download code' ), 'type' => MENU_CALLBACK, 'file' => 'full_download.inc' ); /* COMPLETED om psspS */ $items['powersystems/pssp/completed-pssp'] = array( 'title' => 'Completed Power System Simulations', 'page callback' => 'om_pssp_completed_proposals_all', 'access arguments' => array( 'om pssp download code' ), 'file' => 'pssp_details.inc' ); /* LABS IN PROGRESS */ $items['powersystems/pssp/pssp-progress'] = array( 'title' => 'Power System Simulations in Progress', 'page callback' => 'om_pssp_progress_all', 'access arguments' => array( 'om pssp download code' ), 'file' => 'pssp_details.inc' ); /* DOWNLOAD FOR EVERYONE */ $items['powersystems/pssp/om-pssp-run'] = array( 'title' => 'Download Codes', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_run_form' ), 'access arguments' => array( 'om pssp download code' ), 'type' => MENU_NORMAL_ITEM, 'file' => 'run.inc' ); /* ADMIN SETTINGS */ $items['admin/settings/om-pssp'] = array( 'title' => 'OM PSSP Settings', 'description' => 'OM PSSP Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'om_pssp_settings_form' ), 'access arguments' => array( 'administer om pssp' ), 'type' => MENU_NORMAL_ITEM, 'file' => 'settings.inc' ); /* AJAX REQUEST */ $items['powersystems/pssp/certificates'] = array( 'title' => 'List of Power System Simulation Certificates', 'description' => 'List of Power System Simulation Certificates', 'page callback' => '_list_pssp_certificates', 'access arguments' => array( 'list Power System Simulation certificates' ), 'file' => 'pdf/list_pssp_certificate.inc' ); $items['powersystems/pssp/certificates/generate-pdf'] = array( 'title' => 'Download Certificate', 'description' => 'Download Certificate', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'generate_pdf' ), 'type' => MENU_CALLBACK, 'access arguments' => array( 'generate pdf' ), 'file' => 'pdf/cert_new.inc' ); $items['powersystems/pssp/certificates-custom'] = array( 'title' => 'List of Power System Simulation Custom Certificates', 'description' => 'List of Power System Simulation Custom Certificates', 'page callback' => '_list_pssp_custom_certificates', 'access arguments' => array( 'list Power System Simulation custom certificates' ), 'file' => 'pdf/list_mentor_certificates.inc' ); $items['powersystems/pssp/certificates-custom/pdf'] = array( 'title' => 'Download Certificate', 'description' => 'Download Certificate', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'generate_pdf' ), 'type' => MENU_CALLBACK, 'access arguments' => array( 'generate pdf' ), 'file' => 'pdf/mentor_cert_pdf.inc' ); $items["powersystems/pssp/certificates/verify"] = array( "title" => "Certificate Verification", "page callback" => "verify_certificates", "access arguments" => array( "verify certificates" ), 'type' => MENU_CALLBACK, 'file' => 'pdf/verify_certificates.inc' ); return $items; } /** * Implementation of hook_perm(). */ function om_pssp_permission() { return array( 'om pssp create proposal' => array( 'title' => t('om pssp create proposal'), 'restrict access' => TRUE ), 'om pssp manage proposal' => array( 'title' => t('om pssp manage proposal'), 'restrict access' => TRUE ), 'om pssp edit proposal' => array( 'title' => t('om pssp edit proposal'), 'restrict access' => TRUE ), 'om pssp approve proposal' => array( 'title' => t('om pssp approve proposal'), 'restrict access' => TRUE ), 'om pssp propose solution' => array( 'title' => t('om pssp propose solution'), 'restrict access' => TRUE ), 'om pssp approve abstract' => array( 'title' => t('om pssp approve code'), 'restrict access' => TRUE ), 'om pssp bulk manage abstract' => array( 'title' => t('om pssp bulk manage abstract'), 'restrict access' => TRUE ), 'om pssp bulk delete code' => array( 'title' => t('om pssp bulk delete code'), 'restrict access' => TRUE ), 'om pssp upload code' => array( 'title' => t('om pssp upload code'), 'restrict access' => TRUE ), 'om pssp download code' => array( 'title' => t('om pssp download code'), 'restrict access' => TRUE ), 'administer om pssp' => array( 'title' => t('administer om pssp'), 'restrict access' => TRUE ), 'om pssp generate abstract' => array( 'title' => t('om pssp generate abstract'), 'restrict access' => TRUE ), "list Power System Simulation certificates" => array( "title" => t("list Power System Simulation certificates"), "description" => t("Allows users to list Power System Simulation certificates.") ), "list Power System Simulation custom certificates" => array( "title" => t("list Power System Simulation custom certificates"), "description" => t("Allows users to list Power System Simulation custom certificates.") ), "generate pdf" => array( "title" => t("Generate pdf"), "description" => t("Allows users to Generate pdf.") ) ); // return array('om pssp create proposal', 'om pssp manage proposal', 'om pssp edit proposal', 'om pssp approve proposal', 'om pssp propose solution', 'om pssp approve code', 'om pssp bulk manage abstract', 'om pssp bulk delete code', 'om pssp upload code', 'om pssp download code', 'administer om pssp', 'om pssp generate lab'); } /*************************** VALIDATION FUNCTIONS *****************************/ function om_pssp_check_valid_filename($file_name) { if (!preg_match('/^[0-9a-zA-Z\.\_]+$/', $file_name)) return FALSE; else if (substr_count($file_name, ".") > 1) return FALSE; else return TRUE; } function om_pssp_check_name($name = '') { if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) return FALSE; else return TRUE; } function om_pssp_check_code_number($number = '') { if (!preg_match('/^[0-9]+$/', $number)) return FALSE; else return TRUE; } function om_pssp_path() { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'openmodelica_uploads/om_pssp_uploads/'; } /************************* USER VERIFICATION FUNCTIONS ************************/ function om_pssp_get_proposal() { global $user; //$proposal_q = db_query("SELECT * FROM {om_pssp_proposal} WHERE solution_provider_uid = ".$user->uid." AND solution_status = 2 ORDER BY id DESC LIMIT 1"); $query = db_select('om_pssp_proposal'); $query->fields('om_pssp_proposal'); $query->condition('uid', $user->uid); $query->orderBy('id', 'DESC'); $query->range(0, 1); $proposal_q = $query->execute(); $proposal_data = $proposal_q->fetchObject(); if (!$proposal_data) { drupal_set_message("You do not have any approved om pssp proposal. Please propose the Power System Simulation proposal", 'error'); drupal_goto('powersystems'); } //!$proposal_data switch ($proposal_data->approval_status) { case 0: drupal_set_message(t('Proposal is awaiting approval.'), 'status'); return FALSE; case 1: return $proposal_data; case 2: drupal_set_message(t('Proposal has been dis-approved.'), 'error'); return FALSE; case 3: drupal_set_message(t('Proposal has been marked as completed.'), 'status'); return FALSE; default: drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); return FALSE; } //$proposal_data->approval_status return FALSE; } /*************************************************************************/ /***** Function To convert only first charater of string in uppercase ****/ /*************************************************************************/ function om_pssp_ucname($string) { $string = ucwords(strtolower($string)); foreach (array( '-', '\'' ) as $delimiter) { if (strpos($string, $delimiter) !== false) { $string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string))); } //strpos($string, $delimiter) !== false } //array( '-', '\'' ) as $delimiter return $string; } function _df_sentence_case($string) { $string = ucwords(strtolower($string)); foreach (array( '-', '\'' ) as $delimiter) { if (strpos($string, $delimiter) !== false) { $string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string))); } //strpos($string, $delimiter) !== false } //array( '-', '\'' ) as $delimiter return $string; } function _df_list_of_states() { $states = array( 0 => '-Select-' ); $query = db_select('list_states_of_india'); $query->fields('list_states_of_india'); //$query->orderBy('', ''); $states_list = $query->execute(); while ($states_list_data = $states_list->fetchObject()) { $states[$states_list_data->state] = $states_list_data->state; } //$states_list_data = $states_list->fetchObject() return $states; } function _df_list_of_cities() { $city = array( 0 => '-Select-' ); $query = db_select('list_cities_of_india'); $query->fields('list_cities_of_india'); $query->orderBy('city', 'ASC'); $city_list = $query->execute(); while ($city_list_data = $city_list->fetchObject()) { $city[$city_list_data->city] = $city_list_data->city; } //$city_list_data = $city_list->fetchObject() return $city; } function _df_list_of_pincodes() { $pincode = array( 0 => '-Select-' ); $query = db_select('list_of_all_india_pincode'); $query->fields('list_of_all_india_pincode'); $query->orderBy('pincode', 'ASC'); $pincode_list = $query->execute(); while ($pincode_list_data = $pincode_list->fetchObject()) { $pincode[$pincode_list_data->pincode] = $pincode_list_data->pincode; } //$pincode_list_data = $pincode_list->fetchObject() return $pincode; } function _df_list_of_departments() { $department = array(); $query = db_select('list_of_departments'); $query->fields('list_of_departments'); $query->orderBy('id', 'DESC'); $department_list = $query->execute(); while ($department_list_data = $department_list->fetchObject()) { $department[$department_list_data->department] = $department_list_data->department; } //$department_list_data = $department_list->fetchObject() return $department; } function _df_list_of_software_version() { $software_version = array(); $query = db_select('om_software_version'); $query->fields('om_software_version'); $query->orderBy('id', 'ASC'); $software_version_list = $query->execute(); while ($software_version_list_data = $software_version_list->fetchObject()) { $software_version[$software_version_list_data->om_version] = $software_version_list_data->om_version; } //$software_version_list_data = $software_version_list->fetchObject() return $software_version; } function _df_dir_name($project, $proposar_name) { $project_title = ucname($project); $proposar_name = ucname($proposar_name); $dir_name = $project_title . ' By ' . $proposar_name; $directory_name = str_replace("__", "_", str_replace(" ", "_", str_replace("/", " ", $dir_name))); return $directory_name; } function om_pssp_document_path() { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'openmodelica_uploads/om_pssp_uploads/'; } function DF_RenameDir($proposal_id, $dir_name) { $proposal_id = $proposal_id; $dir_name = $dir_name; $query = db_query("SELECT directory_name,id FROM om_pssp_proposal WHERE id = :proposal_id", array( ':proposal_id' => $proposal_id )); $result = $query->fetchObject(); if ($result != NULL) { $files = scandir(om_pssp_path()); $files_id_dir = om_pssp_path() . $result->id; //var_dump($files);die; $file_dir = om_pssp_path() . $result->directory_name; if (is_dir($file_dir)) { $new_directory_name = rename(om_pssp_path() . $result->directory_name, om_pssp_path() . $dir_name); return $new_directory_name; } //is_dir($file_dir) else if (is_dir($files_id_dir)) { $new_directory_name = rename(om_pssp_path() . $result->id, om_pssp_path() . $dir_name); return $new_directory_name; } //is_dir($files_id_dir) else { drupal_set_message('Directory not available for rename.'); return; } } //$result != NULL else { drupal_set_message('Project directory name not present in databse'); return; } //var_dump($files);die; /* if ($files != NULL) { $new_directory_name = rename(om_pssp_path() . $result->directory_name, om_pssp_path() . $dir_name) or drupal_set_message("Unable to rename folder"); } else { $new_directory_name = 'Can not rename the directory. Directory not present'; }*/ return; } function CreateReadmeFileOmPSSPProject($proposal_id) { $result = db_query(" SELECT * from om_pssp_proposal WHERE id = :proposal_id", array( ":proposal_id" => $proposal_id )); $proposal_data = $result->fetchObject(); $root_path = om_pssp_path(); $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die("Unable to open file!"); $txt = ""; $txt .= "About the Power System Simulation"; $txt .= "\n" . "\n"; $txt .= "Title Of The Power System Simulation Project: " . $proposal_data->project_title . "\n"; $txt .= "Proposar Name: " . $proposal_data->name_title . " " . $proposal_data->contributor_name . "\n"; $txt .= "University: " . $proposal_data->university . "\n"; $txt .= "\n" . "\n"; $txt .= "OM PSSP Project By FOSSEE, IIT Bombay" . "\n"; fwrite($readme_file, $txt); fclose($readme_file); return $txt; } function rrmdir_project($prop_id) { $proposal_id = $prop_id; $result = db_query(" SELECT * from om_pssp_proposal WHERE id = :proposal_id", array( ":proposal_id" => $proposal_id )); $proposal_data = $result->fetchObject(); $root_path = om_pssp_path(); $dir = $root_path . $proposal_data->directory_name; if ($proposal_data->id == $prop_id) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir . "/" . $object) == "dir") { rrmdir($dir . "/" . $object); } //filetype($dir . "/" . $object) == "dir" else { unlink($dir . "/" . $object); } } //$object != "." && $object != ".." } //$objects as $object reset($objects); rmdir($dir); $msg = drupal_set_message("Directory deleted successfully"); return $msg; } //is_dir($dir) $msg = drupal_set_message("Directory not present"); return $msg; } //$proposal_data->id == $prop_id else { $msg = drupal_set_message("Data not found"); return $msg; } } function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir . "/" . $object) == "dir") rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object); } //$object != "." && $object != ".." } //$objects as $object reset($objects); rmdir($dir); } //is_dir($dir) } function _om_pssp_list_of_user_defined_compound($proposal_id) { $data = ""; //$query = db_select('om_pssp_user_defined_compound'); //$query->fields('om_pssp_user_defined_compound'); //$query->condition('proposal_id', $proposal_id, '='); //$query->orderBy('user_defined_compound', 'ASC'); $user_defined_compound_list = db_query("SELECT * FROM om_pssp_user_defined_compound WHERE proposal_id = :proposal_id", array(":proposal_id" => $proposal_id)); $headers = array( "List of user defined compounds used in process Power System Simulation", "CAS No." ); if($user_defined_compound_list){ $rows = array(); while ($row = $user_defined_compound_list->fetchObject()) { $item = array( "{$row->user_defined_compound}", "{$row->cas_no}" ); array_push($rows, $item); } //$row = $user_defined_compound_list->fetchObject() $data .= theme('table', array( 'header' => $headers, 'rows' => $rows )); }else{ $data .= "Not entered"; } return $data; }