"List of converted files from PSPICE to KICAD", "page callback" => "pspice_to_kicad_view", "access arguments" => array( "access pspice_to_kicad", ), "type" => MENU_CALLBACK, ); $items["pspice-to-kicad/description"] = array( "title" => "More Details", "page callback" => "pspice_to_kicad_get_description", "access arguments" => array( "access pspice_to_kicad", ), "type" => MENU_CALLBACK, ); $items["pspice-to-kicad/descriptioninfo"] = array( "title" => "File Details", "page callback" => "pspice_to_kicad_get_descriptioninfo", "access arguments" => array( "convert pspice_to_kicad", ), "type" => MENU_CALLBACK, ); $items['pspice-to-kicad/download/file'] = array( 'title' => 'File Download', 'description' => 'File Download', 'page callback' => 'pspice_to_kicad_download_file', 'access arguments' => array("access pspice_to_kicad"), 'type' => MENU_CALLBACK, ); $items['pspice-to-kicad/download/pdf'] = array( 'title' => 'Description PDF File Download', 'description' => 'Description PDF File Download', 'page callback' => 'pspice_to_kicad_download_pdf_file', 'access arguments' => array("access pspice_to_kicad"), 'type' => MENU_CALLBACK, ); $items["pspice-to-kicad/add"] = array( "title" => "UPLOAD FILES FOR PSPICE TO KICAD CONVERT", "page callback" => "pspice_to_kicad_add_form_display", "access arguments" => array( "manage pspice_to_kicad", ), "type" => MENU_CALLBACK, ); $items["pspice-to-kicad/your-upload"] = array( "title" => "LIST OF FILES UPLOADED BY USER", "page callback" => "pspice_to_kicad_your_uploaded_file", "access arguments" => array( "manage pspice_to_kicad", ), "type" => MENU_CALLBACK, ); $items["pspice-to-kicad/convert"] = array( "title" => "FILES TO BE CONVERTED", "page callback" => "pspice_to_kicad_remain_list", "access arguments" => array( "convert pspice_to_kicad", ), "type" => MENU_CALLBACK, ); $items['pspice-to-kicad/download/pspicefile'] = array( 'title' => 'Pspice File Download', 'description' => 'Pspice File Download', 'page callback' => 'pspice_to_kicad_download_pspice_file', 'access arguments' => array("convert pspice_to_kicad"), 'type' => MENU_CALLBACK, ); $items['pspice-to-kicad/convert/file'] = array( 'title' => 'Convert Files', 'description' => 'Convert Files', 'page callback' => 'pspice_to_kicad_convert_file', 'access arguments' => array("convert pspice_to_kicad"), 'type' => MENU_CALLBACK, ); $items['pspice-to-kicad/delete/file'] = array( 'title' => 'Delete File', 'description' => 'Delete File', 'page callback' => 'pspice_to_kicad_delete_file', 'access arguments' => array("delete pspice_to_kicad file"), 'type' => MENU_CALLBACK, ); $items['pspice-to-kicad/convert/approved'] = array( 'title' => 'Convert Files', 'description' => 'Convert Files', 'page callback' => 'pspice_to_kicad_convert_approved', 'access arguments' => array("convert pspice_to_kicad"), 'type' => MENU_CALLBACK, ); $items['pspice-to-kicad/convert/upload'] = array( 'title' => 'Upload Corrected Zip', 'description' => 'Convert Files', 'page callback' => 'pspice_to_kicad_convert_upload', 'access arguments' => array("convert pspice_to_kicad"), 'type' => MENU_CALLBACK, ); /* ADMIN SETTINGS */ $items['admin/settings/pspice-to-kicad'] = array( 'title' => 'Pspice File Settings', 'description' => 'Pspice File Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'pspicefile_settings_form', ), 'access arguments' => array( 'administer events', ), 'type' => MENU_NORMAL_ITEM, 'file' => 'settings.inc', ); return $items; } function pspice_to_kicad_permission() { return array( "access pspice_to_kicad" => array( "title" => t("Access pspice_to_kicad"), "description" => t("Allows users to view converted."), ), "manage pspice_to_kicad" => array( "title" => t("Upload pspice_to_kicad Files"), "description" => t("Allows users to upload files for pspice to kicad convertor."), ), "convert pspice_to_kicad" => array( "title" => t("Files to be converted"), "description" => t("Allows admin to see files to be convert from pspice to kicad."), ), "delete pspice_to_kicad file" => array( "title" => t("Files to be deleted"), "description" => t("Allows admin to delete files from pspice to kicad."), ), ); } function pspice_to_kicad_check_valid_filename($file_name) { if (preg_match("/\\s/", $file_name)) { return false; } else if (substr_count($file_name, ".") > 1) { return false; } else { return true; } } function pspice_to_kicad_upload_path() { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_uploads/'; } function pspice_to_kicad_convert_path() { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_converts'; } function pspice_to_kicad_add_form_display() { $page_content = ""; $pspice_to_kicad_add_form = drupal_get_form("pspice_to_kicad_add_form"); $page_content = drupal_render($pspice_to_kicad_add_form); return $page_content; } function pspice_to_kicad_add_form($form_state) { $form = array(); $form["codefilename"] = array( '#title' => t('Pspice File'), '#type' => 'file', '#weight' => '1', '#description' => t(''), ); $form["description"] = array( "#type" => "textarea", "#required" => true, '#weight' => '2', "#title" => "Description", '#description' => t(''), ); $form['pdffilename'] = array( '#title' => t('PDF File'), '#type' => 'file', '#weight' => '3', '#description' => t(''), ); $form['termsandcondition'] = array( '#type' => 'checkbox', '#title' => t('Terms and Conditions'), '#weight' => '4', "#required" => true, ); $form['termsandcondition_text'] = array( '#type' => 'markup', '#weight' => '5', '#markup' => t(' Note: All uploaded PSpice files will be deleted from our database after converting them to KiCad files.

'), ); $form["submit"] = array( "#type" => "submit", '#weight' => '6', "#value" => "Submit", ); return $form; } function pspice_to_kicad_add_form_validate($form, &$form_state) { if (isset($_FILES['files'])) { /* check if atleast one source or result file is uploaded */ if (!($_FILES['files']['name']['codefilename'])) { form_set_error('codefilename', t('Please upload Pspice file.')); } foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { if ($file_name) { /* checking file type */ if (strstr($file_form_name, 'code')) { $file_type = 'P'; } else if (strstr($file_form_name, 'pdf')) { $file_type = 'D'; } else { $file_type = 'U'; } $allowed_extensions_str = ''; switch ($file_type) { case 'P': $allowed_extensions_str = variable_get('pspice_files_extensions', ''); break; case 'D': $allowed_extensions_str = variable_get('pdfpspicefile_files_extensions', ''); break; } $allowed_extensions = explode(',', $allowed_extensions_str); $allowed_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); $temp_extension = end($allowed_ext); if (!in_array($temp_extension, $allowed_extensions)) { form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); } if ($_FILES['files']['size'][$file_form_name] <= 0) { form_set_error($file_form_name, t('File size cannot be zero.')); } /* check if valid file name */ if (!pspice_to_kicad_check_valid_filename($_FILES['files']['name'][$file_form_name])) { form_set_error($file_form_name, t('Invalid file name specified. No Space are allowed in a filename.')); } } } } } function pspice_to_kicad_add_form_submit($form, &$form_state) { global $user; if (!$user->uid) { drupal_set_message('It is mandatory to login on this website to upload files for converting', 'error'); return; } $v = $form_state["values"]; $filesupload = 0; $i = 0; $uploadresult = 0; /*Creating folder for saving uploaded files */ $upload_root_path = pspice_to_kicad_upload_path(); $eventfolder = $user->uid; $dest_path = $eventfolder . '/'; if (!is_dir($upload_root_path . $dest_path)) { mkdir($upload_root_path . $dest_path); } foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { if (strlen(trim($v["description"])) >= 49 && strlen(trim($v["description"])) <= 200) { $temp = explode(".", $file_name); $newuploadfilename = $file_name; /*for uploading*/ if ($newuploadfilename) { if ($file_form_name != "pdffilename") { if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) { drupal_set_message(t("Error uploading file. File !filename already exists. Please give different relevant name", array( '!filename' => $newuploadfilename, )), 'error'); return; } } else { $newuploadfilename = str_replace(' ', '_', trim($newuploadfilename . "@" . date("Y-m-d H:i:s"))); } /* uploading file */ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $upload_root_path . $dest_path . $newuploadfilename)) { if ($file_form_name != "pdffilename") { $uploadquery = " INSERT INTO custom_kicad_convertor (uid,caption,description,upload_filename,upload_filepath,upload_filemime,upload_filesize,upload_date,converted_filename, converted_filepath,converted_filemime,converted_filesize,converted_date,converted_flag,download_counter) VALUES (:uid,:caption,:description,:upload_filename,:upload_filepath,:upload_filemime,:upload_filesize,:upload_date,:converted_filename, :converted_filepath,:converted_filemime,:converted_filesize,:converted_date,:converted_flag,:download_counter) "; $uploadargs = array( ":uid" => $user->uid, ":caption" => "None", ":description" => trim($v["description"]), ":upload_filename" => $newuploadfilename, ":upload_filepath" => $dest_path . $newuploadfilename, ":upload_filemime" => file_get_mimetype($newuploadfilename), ":upload_filesize" => $_FILES['files']['size'][$file_form_name], ":upload_date" => date("Y-m-d H:i:s"), ":converted_filename" => "None", ":converted_filepath" => "None", ":converted_filemime" => "None", ":converted_filesize" => 0, ":converted_date" => date("Y-m-d H:i:s"), ":converted_flag" => 0, ":download_counter" => 0, ); /* storing the row id in $result */ $uploadresult = db_query($uploadquery, $uploadargs, array( 'return' => Database::RETURN_INSERT_ID, )); } else { $updatequery = db_update('custom_kicad_convertor'); $updatequery->fields(array( 'description_pdf_path' => $dest_path . $newuploadfilename, )); $updatequery->condition('id', $uploadresult); $updateresult = $updatequery->execute(); } if ($file_form_name != "pdffilename") { if ($uploadresult != 0) { $filesupload++; /* sending mail */ $user_data = user_load($user->uid); $to = $user_data->mail; $from = variable_get('kicad_from_email', ''); $bcc = variable_get('kicad_emails', ''); $cc = variable_get('kicad_cc_emails', ''); $subject = "[esim.in][PSpice to KiCad Converter] Successful upload of PSpice schematic"; $email_body = " Dear " . $user_data->name . ", You have uploaded the following PSpice schematic: File : " . $newuploadfilename . " We shall review it and convert the schematic into KiCad format. You will be notified once the file is converted. Best Wishes,
" . variable_get('site_name', '') . " Team,
FOSSEE, IIT Bombay"; send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body, $from, $bcc, $cc); } } } else { drupal_set_message('Error uploading file : ' . $dest_path . $newuploadfilename, 'error'); } } } else { form_set_error('description', t('Minimum 50 character and Maximum 200 character for description')); return; } } if ($filesupload != 0) { drupal_set_message('File uploaded successfully. Please check your register email for more details.', 'status'); } } function pspice_to_kicad_remain_list() { $convertor_CSS = " .convert_button { display: block; width: 80px; height: 25px; background:#156aa3; padding: 2px; text-align: center; border-radius: 5px; color: white; } "; drupal_add_css($convertor_CSS, 'inline', 'header'); $caption = "

List of files to be converted:

"; $output = ""; $query = ""; $count_query = ""; $rows = array(); $header = array( array('data' => 'Uploaded Date', 'field' => 'ckc.upload_date', 'sort' => 'desc'), array('data' => 'File'), array('data' => ''), array('data' => ''), array('data' => ''), array('data' => ''), ); $query = db_select('custom_kicad_convertor', 'ckc'); $query->fields('ckc', array('id', 'uid', 'upload_date', 'upload_filename', 'upload_filepath')); $query->condition('ckc.converted_flag', 2, '<>'); $result = $query->extend('PagerDefault')->limit(20)->extend('TableSort')->orderByHeader($header)->execute(); $number_of_rows = $result->rowCount(); while ($row = $result->fetchObject()) { $filearray = explode('.', $row->upload_filename); $filenamewothoutext = $filearray[0]; $filename = $filenamewothoutext; $item = array(date('d-m-Y', strtotime($row->upload_date)), "" . $filename . "", l(t('Convert'), '/pspice-to-kicad/convert/file/' . $row->id, array('attributes' => array('class' => array('convert_button'), 'title' => 'Click to convert file'))), l(t('Delete'), '/pspice-to-kicad/delete/file/' . $row->id, array('attributes' => array('class' => array('convert_button'), 'title' => 'Click to delete file'))), l(t('Upload'), '/pspice-to-kicad/convert/upload/' . $row->id, array('attributes' => array('class' => array('convert_button'), 'title' => 'Click to upload corrected file'))), l(t('Publish'), '/pspice-to-kicad/convert/approved/' . $row->id, array('attributes' => array('class' => array('convert_button'), 'title' => 'Click to publish file'))), ); array_push($rows, $item); } if ($number_of_rows == 0) { $output .= '
No files for convert
'; } else { $build['pager_table'] = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, '#caption' => $caption, '#attributes' => array( 'class' => array('table table-bordered table-hover'), ), ); // Attach the pager theme. $build['pager_pager'] = array('#theme' => 'pager'); $output = $build; } return $output; } function pspice_to_kicad_view() { $caption = "

List of Converted files:

"; $output = ""; $query = ""; $count_query = ""; $rows = array(); $header = array( array('data' => 'Date'), array('data' => 'Uploaded by'), array('data' => 'Download'), array('data' => ''), ); $query = db_select('custom_kicad_convertor', 'ckc'); $query->fields('ckc', array('id', 'uid', 'caption', 'description', 'converted_filename' , 'converted_filepath', 'converted_date', 'download_counter')); $query->condition('ckc.converted_flag', 2); $query->orderBy('converted_date', 'DESC'); $result = $query->extend('PagerDefault')->limit(10)->extend('TableSort')->orderByHeader($header)->execute(); $number_of_rows = $result->rowCount(); while ($row = $result->fetchObject()) { $query = db_select('users'); $query->fields('users'); $query->condition('uid', $row->uid); $user = $query->execute(); $user_data = $user->fetchObject(); $item = array(date('d-m-Y', strtotime($row->converted_date)), $user_data->name, l($row->converted_filename, '/pspice-to-kicad/download/file/' . $row->id, array('attributes' => array('title' => 'Click to download converted file'))), "Detail", ); array_push($rows, $item); } if ($number_of_rows == 0) { $output .= '
No files available yet for download
'; } else { $build['pager_table'] = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, '#caption' => $caption, '#attributes' => array( 'class' => array('table table-bordered table-hover'), ), ); // Attach the pager theme. $build['pager_pager'] = array('#theme' => 'pager'); $output = $build; } return $output; } function pspice_to_kicad_download_file() { $id = arg(3); $root_path = pspice_to_kicad_convert_path(); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $id); $query->range(0, 1); $files_q = $query->execute(); $file_data = $files_q->fetchObject(); $earlier_count = $file_data->download_counter; $download_counter = 1; $updatequery = db_update('custom_kicad_convertor'); $updatequery->fields(array( 'download_counter' => $earlier_count + $download_counter, )); $updatequery->condition('id', $id); $updateresult = $updatequery->execute(); header('Content-Type: ' . $file_data->converted_filemime); header('Content-disposition: attachment; filename="' . $file_data->converted_filename . '"'); header('Content-Length: ' . filesize($root_path . "/" . $file_data->converted_filepath)); ob_clean(); flush(); readfile($root_path . "/" . $file_data->converted_filepath); } function send_mail($from, $to, $subject, $message, $from1, $bcc, $cc) { $my_module = 'pspice_to_kicad'; $my_mail_token = microtime(); $message = array( 'id' => $my_module . '_' . $my_mail_token, 'to' => $to, 'subject' => $subject, 'body' => array($message), 'headers' => array( 'From' => $from1, 'Return-Path' => $from1, 'Bcc' => $bcc, 'Cc' => $cc, ), ); $system = drupal_mail_system($my_module, $my_mail_token); $message = $system->format($message); if ($system->mail($message)) { return true; } else { return false; } } function pspice_to_kicad_convert_file() { try { $upload_root_path = pspice_to_kicad_upload_path(); $convert_root_path = pspice_to_kicad_convert_path(); $fileid = arg(3); $query = db_select('custom_kicad_convertor', 'ckc'); $query->fields('ckc', array('id', 'uid', 'caption', 'upload_date', 'upload_filename', 'upload_filepath')); $query->condition('id', $fileid); $result = $query->execute(); $row = $result->fetchObject(); $file = $row->upload_filename; $filearray = explode('.', $file); $filenamewothoutext = $filearray[0]; $filenamearray = explode('.', $row->upload_filepath); $filename = $filenamearray[0]; $filePath = $upload_root_path . "" . $row->upload_filepath; $uploadfolder = $row->uid; exec("/Sites/esim_in/sites/all/modules/pspice_to_kicad/convert.sh " . $convert_root_path . " " . $filePath . " " . $uploadfolder, $outputFiles); $file = $row->upload_filename; $filearray = explode('.', $file); $converted_file = $convert_root_path . "/" . $filename . ".zip"; $query = db_update('custom_kicad_convertor'); $query->fields(array( 'converted_filename' => $filenamewothoutext . ".zip", 'converted_filepath' => $filename . ".zip", 'converted_filemime' => file_get_mimetype($converted_file), 'converted_filesize' => filesize($converted_file), 'converted_date' => date("Y-m-d H:i:s"), 'converted_flag' => "1", )); $query->condition('id', $row->id); $result = $query->execute(); header('Content-Type: ' . file_get_mimetype($converted_file)); header('Content-disposition: attachment; filename="' . $filenamewothoutext . ".zip" . '"'); header('Content-Length: ' . filesize($converted_file)); ob_clean(); flush(); readfile($converted_file); } catch (Exception $e) { drupal_set_message('Error while converting file, Please download specific file by clicking on file and Check it manually', 'error'); drupal_goto("pspice-to-kicad/convert"); return; } } function pspice_to_kicad_convert_approved() { $fileid = arg(3); $number_of_rows = 0; $querycheck = db_select('custom_kicad_convertor'); $querycheck->fields('custom_kicad_convertor'); $querycheck->condition('id', $fileid); $querycheck->condition('converted_flag', "1"); $resultcheck = $querycheck->execute(); $number_of_rows = $resultcheck->rowCount(); if ($number_of_rows != 0) { $query = db_update('custom_kicad_convertor'); $query->fields(array( 'converted_flag' => "2", )); $query->condition('id', $fileid); $result = $query->execute(); if ($result) { $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $fileid); $result = $query->execute(); $row = $result->fetchObject(); $upload_root_path = pspice_to_kicad_upload_path(); $eventfolder = $row->uid; $dest_path = $eventfolder . '/'; $newuploadfilename = $row->upload_filename; if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) { unlink($upload_root_path . $dest_path . $newuploadfilename); } $user_data = user_load($row->uid); $to = $user_data->mail; $from = variable_get('kicad_from_email', ''); $bcc = variable_get('kicad_emails', ''); $cc = variable_get('kicad_cc_emails', ''); $subject = "[esim.in][PSpice to KiCad Converter] PSpice file converted successfully"; $email_body = " Dear " . $user_data->name . ", The uploaded PSpice file " . $row->upload_filename . " is successfully converted to Kicad format. This can be used in https://esim.fossee.in . You can download the converted file from https://esim.fossee.in/pspice-to-kicad/download/file/" . $fileid . " Best Wishes,
" . variable_get('site_name', '') . " Team,
FOSSEE, IIT Bombay"; send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body, $from, $bcc, $cc); } } else { drupal_set_message('File should be converted before Publishing', 'error'); } drupal_goto("pspice-to-kicad/convert"); return; } function pspice_to_kicad_convert_upload() { $fileid = arg(3); $number_of_rows = 0; $querycheck = db_select('custom_kicad_convertor'); $querycheck->fields('custom_kicad_convertor'); $querycheck->condition('id', $fileid); $querycheck->condition('converted_flag', "1"); $resultcheck = $querycheck->execute(); $number_of_rows = $resultcheck->rowCount(); $page_content = ""; if ($number_of_rows != 0) { $pspice_to_kicad_upload_form = drupal_get_form("pspice_to_kicad_upload_form", $fileid); $page_content = drupal_render($pspice_to_kicad_upload_form); return $page_content; } else { drupal_set_message('File should be converted first
If automated converted file has error, you can upload corrected zip file using this feature.', 'error'); drupal_goto("pspice-to-kicad/convert"); return; } } function pspice_to_kicad_upload_form($form, &$form_state, $fileid) { $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $fileid); $result = $query->execute(); $row = $result->fetchObject(); $form = array(); $form['pspice_uploadfiles_fieldset'] = array( '#type' => 'fieldset', '#tree' => true, '#prefix' => '
', '#suffix' => '
', ); $form['pspice_uploadfiles_fieldset']["file_description"] = array( "#type" => "textarea", "#default_value" => $row->description, "#title" => "Description", "#required" => true, '#description' => t(''), ); $form['pspice_uploadfiles_fieldset']['name'] = array( '#title' => t('Upload File'), '#type' => 'file', '#weight' => '5', '#description' => t(''), ); $form["pspice_files_id"] = array( "#type" => "hidden", "#value" => $fileid, ); $form["submit"] = array( "#type" => "submit", "#value" => "Submit", ); return $form; } function pspice_to_kicad_upload_form_validate() { if (isset($_FILES['files'])) { /* check for valid filename extensions */ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { if ($file_name) { if (strstr($file_form_name, 'pspice_uploadfiles_fieldset')) { $file_type = 'P'; } switch ($file_type) { case 'P': $allowed_extensions_str = variable_get('kicad_corrected_files_extensions', ''); break; } $allowed_extensions = explode(',', $allowed_extensions_str); $allowed_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); $temp_extension = end($allowed_ext); if (!in_array($temp_extension, $allowed_extensions)) { form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); } if (($_FILES['files']['size'][$file_form_name] == 0)) { form_set_error($file_form_name, t('File with 0 byte size cannot be uploaded.')); } if (!pspice_to_kicad_check_valid_filename($_FILES['files']['name'][$file_form_name])) { form_set_error($file_form_name, t('Invalid file name specified. No Space are allowed in a filename.')); } } } } } function pspice_to_kicad_upload_form_submit($form, &$form_state) { global $user; $v = $form_state["values"]; $filesupload = 0; $i = 0; $id = $v["pspice_files_id"]; $arr = array_values($_FILES['files']['name']); if (strlen(trim($arr[0])) <= 0) { drupal_set_message('Please corrected zip file', 'error'); return; } $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $id); $result = $query->execute(); $row = $result->fetchObject(); /*Creating folder for saving uploaded files */ $convert_root_path = pspice_to_kicad_convert_path() . "/"; $eventfolder = $row->uid; $dest_path = $eventfolder . '/'; if (!is_dir($convert_root_path . $dest_path)) { mkdir($convert_root_path . $dest_path); } foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { $temp = explode(".", $file_name); $newuploadfilename = $file_name; /*for uploading*/ if ($newuploadfilename) { if (file_exists($convert_root_path . $dest_path . $newuploadfilename)) { unlink($convert_root_path . $dest_path . $newuploadfilename); } /* uploading file */ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $convert_root_path . $dest_path . $newuploadfilename)) { $updatequery = db_update('custom_kicad_convertor'); $updatequery->fields(array( "description" => trim($v['pspice_uploadfiles_fieldset']["file_description"]), "converted_filename" => $newuploadfilename, "converted_filepath" => $dest_path . $newuploadfilename, "converted_filemime" => file_get_mimetype($newuploadfilename), "converted_filesize" => $_FILES['files']['size'][$file_form_name], "converted_date" => date("Y-m-d H:i:s"), "converted_flag" => 1, )); $updatequery->condition('id', $id); $updateresult = $updatequery->execute(); drupal_set_message($newuploadfilename . ' uploaded successfully.', 'status'); } else { drupal_set_message('Error uploading file : ' . $dest_path . $newuploadfilename, 'error'); } } } drupal_goto("pspice-to-kicad/convert"); return; } function pspice_to_kicad_get_description($file_id = 0) { $pagecontent = ""; $fileid = arg(2); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $fileid); $result = $query->execute(); $row = $result->fetchObject(); $pdffilearray = explode('@', $row->description_pdf_path); $pdffilenamepath = $pdffilearray[0]; $pdffilearray2 = explode('/', $pdffilenamepath); $pdffilename = $pdffilearray2[1]; $pagecontent .= "

Brief Description of file : " . $row->description . "

"; if ($row->description_pdf_path != "" || $row->description_pdf_path != null) { $pagecontent .= " PDF File with description : id . "'>" . $pdffilename . ""; } return $pagecontent; } function pspice_to_kicad_get_descriptioninfo($file_id = 0) { $pagecontent = ""; $fileid = arg(2); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $fileid); $result = $query->execute(); $row = $result->fetchObject(); $queryuser = db_select('users'); $queryuser->fields('users'); $queryuser->condition('uid', $row->uid); $user = $queryuser->execute(); $user_data = $user->fetchObject(); $filearray = explode('.', $row->upload_filename); $filenamewothoutext = $filearray[0]; $filename = $filenamewothoutext; $pdffilearray = explode('@', $row->description_pdf_path); $pdffilenamepath = $pdffilearray[0]; $pdffilearray2 = explode('/', $pdffilenamepath); $pdffilename = $pdffilearray2[1]; $pagecontent .= "

File name : " . $filename . "

"; $pagecontent .= "

Author : " . $user_data->name . "

"; $pagecontent .= "

Upload Date : " . date('d-m-Y', strtotime($row->upload_date)) . "

"; $pagecontent .= "

Description : " . $row->description . "

"; $pagecontent .= "Pspice File : id . "'>" . $row->upload_filename . "

"; if ($row->description_pdf_path != "" || $row->description_pdf_path != null) { $pagecontent .= "Description PDF File : id . "'>" . $pdffilename . ""; } return $pagecontent; } function pspice_to_kicad_your_uploaded_file() { global $user; $output = ""; $query = ""; $count_query = ""; $rows = array(); $header = array( array('data' => 'Date', 'field' => 'ckc.upload_date', 'sort' => 'desc'), array('data' => 'File name'), array('data' => 'Conversion Status'), array('data' => ''), ); $query = db_select('custom_kicad_convertor', 'ckc'); $query->fields('ckc', array('id', 'uid', 'description', 'upload_filename', 'converted_flag' , 'upload_date')); $query->condition('ckc.uid', $user->uid); $result = $query->extend('PagerDefault')->limit(10)->extend('TableSort')->orderByHeader($header)->execute(); $number_of_rows = $result->rowCount(); while ($row = $result->fetchObject()) { $converted_flag = $row->converted_flag; $status = ""; if ($converted_flag == 1 || $converted_flag == 0) { $status = "In Process"; } else { $status = "Converted"; } $item = array(date('d-m-Y', strtotime($row->upload_date)), $row->upload_filename, $status, "Detail", ); array_push($rows, $item); } if ($number_of_rows == 0) { $output .= '
No files has been uploaded by you
'; } else { $build['pager_table'] = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array( 'class' => array('table table-bordered table-hover'), ), ); // Attach the pager theme. $build['pager_pager'] = array('#theme' => 'pager'); $output = $build; } return $output; } function pspice_to_kicad_download_pdf_file() { $id = arg(3); $root_path = pspice_to_kicad_upload_path(); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $id); $query->range(0, 1); $files_q = $query->execute(); $file_data = $files_q->fetchObject(); $pdffilearray = explode('@', $file_data->description_pdf_path); $pdffilenamepath = $pdffilearray[0]; $pdffilearray2 = explode('/', $pdffilenamepath); $pdffilename = $pdffilearray2[1]; header('Content-Type: application/pdf'); header('Content-disposition: attachment; filename="' . $pdffilename . '"'); header('Content-Length: ' . filesize($root_path . "/" . $file_data->description_pdf_path)); ob_clean(); flush(); readfile($root_path . "/" . $file_data->description_pdf_path); } function pspice_to_kicad_download_pspice_file() { $id = arg(3); $root_path = pspice_to_kicad_upload_path(); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); $query->condition('id', $id); $query->range(0, 1); $files_q = $query->execute(); $file_data = $files_q->fetchObject(); header('Content-Type:' . $file_data->upload_filemime); header('Content-disposition: attachment; filename="' . $file_data->upload_filename . '"'); header('Content-Length: ' . filesize($root_path . $file_data->upload_filepath)); ob_clean(); flush(); readfile($root_path . $file_data->upload_filepath); } function pspice_to_kicad_delete_file() { $fileid = arg(3); $number_of_rows = 0; $querycheck = db_select('custom_kicad_convertor'); $querycheck->fields('custom_kicad_convertor'); $querycheck->condition('id', $fileid); $resultcheck = $querycheck->execute(); $number_of_rows = $resultcheck->rowCount(); $page_content = ""; if ($number_of_rows != 0) { $pspice_to_kicad_delete_file_form = drupal_get_form("pspice_to_kicad_delete_file_form", $fileid); $page_content = drupal_render($pspice_to_kicad_delete_file_form); return $page_content; } else { drupal_set_message('File can not be deleted. Please contact to site administrator', 'error'); drupal_goto("pspice-to-kicad/convert"); return; } } function pspice_to_kicad_delete_file_form($form, &$form_state, $fileid) { $querycheck = db_select('custom_kicad_convertor'); $querycheck->fields('custom_kicad_convertor'); $querycheck->condition('id', $fileid); $resultcheck = $querycheck->execute(); $number_of_rows = $resultcheck->rowCount(); $form = array(); $form['pspice_deletefile_fieldset'] = array( '#type' => 'fieldset', '#tree' => true, '#prefix' => '
', '#suffix' => '
', ); $form['pspice_deletefile_fieldset']["reason"] = array( "#type" => "textarea", "#default_value" => "", "#title" => "Reason for deletion of file: ", "#required" => true, '#description' => t(''), ); $form["pspice_files_id"] = array( "#type" => "hidden", "#value" => $fileid, ); $form["submit"] = array( "#type" => "submit", "#value" => "Submit", "#attributes" => array('onclick' => 'if(!confirm("Do you really want to delete this file ?")){history.go(-1);return false;}'), ); return $form; } function pspice_to_kicad_delete_file_form_validate() { } function pspice_to_kicad_delete_file_form_submit($form, &$form_state) { global $user; $v = $form_state["values"]; $id = $v["pspice_files_id"]; $fileid = $id; $querycheck = db_select('custom_kicad_convertor'); $querycheck->fields('custom_kicad_convertor'); $querycheck->condition('id', $fileid); $resultcheck = $querycheck->execute(); $row = $resultcheck->fetchObject(); $upload_root_path = pspice_to_kicad_upload_path(); $eventfolder = $row->uid; $dest_path = $eventfolder . '/'; $newuploadfilename = $row->upload_filename; if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) { unlink($upload_root_path . $dest_path . $newuploadfilename); } if (file_exists($upload_root_path . $row->description_pdf_path)) { unlink($upload_root_path . $row->description_pdf_path); } //Deleting DB entry of that file. db_delete('custom_kicad_convertor')->condition('id', $row->id)->execute(); $user_data = user_load($row->uid); $to = $user_data->mail; $from = variable_get('kicad_from_email', ''); $bcc = variable_get('kicad_emails', ''); $cc = variable_get('kicad_cc_emails', ''); $subject = "[esim.in][PSpice to KiCad Converter] PSpice to KiCad converter: Uploaded schematic file deleted"; $email_body = " Dear " . $user_data->name . ", Thank you for using the PSpice to KiCad converter. We have deleted your uploaded schematic file with the following details: Schematic name : " . $row->upload_filename . " Description: " . $row->description . " Reason of Deletion : " . trim($v['pspice_deletefile_fieldset']['reason']) . " You are welcome to upload a new Pspice schematic file for conversion. Best Wishes,
" . variable_get('site_name', '') . " Team,
FOSSEE, IIT Bombay"; send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body, $from, $bcc, $cc); drupal_set_message('File is deleted successfully and an email has send to file author.', 'status'); drupal_goto("pspice-to-kicad/convert"); return; }