diff options
-rwxr-xr-x[-rw-r--r--] | .gitignore | 0 | ||||
-rwxr-xr-x | convert.sh | 29 | ||||
m--------- | eSim_PSpice_to_KiCad_Python_Parser | 0 | ||||
-rwxr-xr-x | pspice_to_kicad.module | 306 |
4 files changed, 207 insertions, 128 deletions
diff --git a/.gitignore b/.gitignore index 1e2b44b..1e2b44b 100644..100755 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,21 @@ #!/bin/bash #Log file location -log="/var/log/psicekicad.log" +log="/tmp/psicekicad.log" +cmd_path1="/home/prashant/www/html/drupal/drupal_7.x/r_fossee_in/sites/all/modules/custom/pspice_to_kicad/" +cmd_path2="eSim_PSpice_to_KiCad_Python_Parser/lib/PythonLib/" +parser_command="parser.py " echo "###########Start Conversion from PSPICE to KICAD#################" >> $log echo "" >>$log echo "The Conversion starts at `date`" >> $log ####Getting Parameter -convertedSchematic=$1 -filepath=$2 -username=$3 +convertedSchematic=$1 +filepath=$2 +username=$3 cwd=`pwd` +echo $filepath +echo $convertedSchematic echo "">>$log echo "The paramters to the script is : ">>$log @@ -25,29 +30,29 @@ echo "">>$log #Create Directory for every User -if [ -d $convertedSchematic/$username ];then - echo "User directory $username is already available">>$log +if [ -d $convertedSchematic ];then + echo "User directory $convertedSchematic is already available">>$log else - mkdir -p $convertedSchematic/$username + mkdir -p $convertedSchematic fi -echo "The converted file will be present at $convertedSchematic/$username">>$log +echo "The converted file will be present at $convertedSchematic">>$log #Creating directory for uploaded Project -mkdir -p $convertedSchematic/$username/$filewithoutExt +mkdir -p $convertedSchematic/$filewithoutExt #Converting PSpice to Kicad Schematic echo "Calling Schematic conversion script" >>$log -/var/www/html/esim_in/sites/all/modules/pspice_to_kicad/schConverter64 $filepath $convertedSchematic/$username/$filewithoutExt/$filename 2>&1>>$log +python3.7 $cmd_path1$cmd_path2$parser_command $filepath $convertedSchematic/$filewithoutExt #Converting to Zip file -cd $convertedSchematic/$username +cd $convertedSchematic #sudo zip -rq -rm $zipname $filewithoutExt echo "Creating zip file of converted project">>$log zip -r $filewithoutExt{.zip,} 2>&1>>$log echo "The zip file is present at `pwd`">>$log cd $cwd -rm -rf $convertedSchematic/$username/$filewithoutExt +rm -rf $convertedSchematic/$filewithoutExt echo "###########End PSICE to KICAD Conversion#########################">>$log echo " ">>$log diff --git a/eSim_PSpice_to_KiCad_Python_Parser b/eSim_PSpice_to_KiCad_Python_Parser new file mode 160000 +Subproject a8b143691767d9592306c2bfadc326b042520b2 diff --git a/pspice_to_kicad.module b/pspice_to_kicad.module index 79371d1..34152fe 100755 --- a/pspice_to_kicad.module +++ b/pspice_to_kicad.module @@ -146,9 +146,9 @@ function pspice_to_kicad_permission() "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."), - ), + "title" => t("Files to be deleted"), + "description" => t("Allows admin to delete files from pspice to kicad."), + ), ); } @@ -166,14 +166,68 @@ function pspice_to_kicad_check_valid_filename($file_name) } -function pspice_to_kicad_upload_path() +function pspice_to_kicad_directroy_path() { - return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_uploads/'; + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_uploads'; +} +function pspice_to_kicad_user_upload_path() +{ + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_uploads/pspice_to_kicad_user_uploads/'; } - function pspice_to_kicad_convert_path() { - return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_converts'; + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_uploads/pspice_to_kicad_converts/'; +} + +function get_directory($uid, $fid) +{ + $upload_root_path = pspice_to_kicad_directroy_path(); + $dir1 = $upload_root_path . '/' . $uid; + if (!is_dir($dir1)) { + mkdir($dir1); + } + $dir2 = $dir1 . '/' . $fid; + if (!is_dir($dir2)) { + mkdir($dir2); + } + $dir3 = $dir2 . '/' . 'pspice_to_kicad_user_uploads'; + if (!is_dir($dir3)) { + mkdir($dir3); + } + $dir4 = $dir2 . '/' . 'pspice_to_kicad_converts'; + if (!is_dir($dir4)) { + mkdir($dir4); + } + return true; +} +/* $flag= 1 is upload, $flag=2 is for convert */ +function get_directory_path($uid, $fid, $flag) +{ + $upload_root_path = pspice_to_kicad_directroy_path(); + if ($flag == 1) { + $dir_upload = $upload_root_path . '/' . $uid . '/' . $fid . '/' . 'pspice_to_kicad_user_uploads'; + if (is_dir($dir_upload)) { + return $dir_upload; + } + } elseif ($flag == 2) { + $dir_conv = $upload_root_path . '/' . $uid . '/' . $fid . '/' . 'pspice_to_kicad_converts'; + if (is_dir($dir_conv)) { + return $dir_conv; + } + } elseif ($flag == 3) { + $dir_conv = $upload_root_path . '/' . $uid . '/' . $fid . '/' . 'pspice_to_kicad_user_uploads'; + if (is_dir($dir_conv)) { + return $uid . '/' . $fid . '/' . 'pspice_to_kicad_user_uploads'; + } + } elseif ($flag == 4) { + $dir_conv = $upload_root_path . '/' . $uid . '/' . $fid . '/' . 'pspice_to_kicad_converts'; + if (is_dir($dir_conv)) { + return $uid . '/' . $fid . '/' . 'pspice_to_kicad_converts'; + } + } else { + drupal_set_message('Directory not available. Contact site administrator ', 'error'); + return flase; + } } function pspice_to_kicad_add_form_display() @@ -184,7 +238,7 @@ function pspice_to_kicad_add_form_display() return $page_content; } -function pspice_to_kicad_add_form($form_state) +function pspice_to_kicad_add_form($form, &$form_state) { $form = array(); @@ -209,7 +263,6 @@ function pspice_to_kicad_add_form($form_state) '#type' => 'file', '#weight' => '3', '#description' => t('<label Style="color:red">Note: Please upload any other supplementary document like experiment details/ lab manual/ analysis parameter details of the schematic here (Not mandatory)<br>Only PDF file can be uploaded</label>'), - ); $form['termsandcondition'] = array( @@ -286,7 +339,7 @@ function pspice_to_kicad_add_form_validate($form, &$form_state) /* 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.')); + a filename.')); } } @@ -308,16 +361,43 @@ function pspice_to_kicad_add_form_submit($form, &$form_state) $v = $form_state["values"]; $filesupload = 0; $i = 0; - $uploadresult = 0; + $uploaddataresult = 0; + $upload_root_path = pspice_to_kicad_directroy_path(); + $uploaddataquery = " + 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) + "; + $uploaddataargs = array( + ":uid" => $user->uid, + ":caption" => "None", + ":description" => trim($v["description"]), + ":upload_filename" => "None", + ":upload_filepath" => "None", + ":upload_filemime" => "None", + ":upload_filesize" => 0, + ":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, - /*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); - } + ); + /* storing the row id in $result */ + $uploaddataresult = db_query($uploaddataquery, $uploaddataargs, array( + 'return' => Database::RETURN_INSERT_ID, + )); + get_directory($user->uid, $uploaddataresult); + $new_dest_path = get_directory_path($user->uid, $uploaddataresult, 3); + $get_absolute_path = get_directory_path($user->uid, $uploaddataresult, 1); + //var_dump($new_dest_path);die; foreach ($_FILES['files']['name'] as $file_form_name => $file_name) { if (strlen(trim($v["description"])) >= 49 && strlen(trim($v["description"])) <= 200) { @@ -329,7 +409,7 @@ function pspice_to_kicad_add_form_submit($form, &$form_state) if ($newuploadfilename) { if ($file_form_name != "pdffilename") { - if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) { + if (file_exists($get_absolute_path . '/' . $newuploadfilename)) { drupal_set_message(t("Error uploading file. File !filename already exists. Please give different relevant name", array( '!filename' => $newuploadfilename, )), 'error'); @@ -343,55 +423,43 @@ function pspice_to_kicad_add_form_submit($form, &$form_state) /* uploading file */ - if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $upload_root_path . - $dest_path . $newuploadfilename)) { + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $get_absolute_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, + $updatequery = db_update('custom_kicad_convertor'); + $updatequery->fields(array( + "uid" => $user->uid, + "caption" => "None", + "description" => trim($v["description"]), + "upload_filename" => $newuploadfilename, + "upload_filepath" => $new_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, )); + $updatequery->condition('id', $uploaddataresult); + $updatequery->execute(); } else { $updatequery = db_update('custom_kicad_convertor'); $updatequery->fields(array( - 'description_pdf_path' => $dest_path . $newuploadfilename, + 'description_pdf_path' => $new_dest_path . '/' . $newuploadfilename, )); - $updatequery->condition('id', $uploadresult); + $updatequery->condition('id', $uploaddataresult); $updateresult = $updatequery->execute(); } if ($file_form_name != "pdffilename") { - if ($uploadresult != 0) { + if ($uploaddataresult != 0) { $filesupload++; /* sending mail */ @@ -423,7 +491,7 @@ FOSSEE, IIT Bombay"; } } else { - drupal_set_message('Error uploading file : ' . $dest_path . $newuploadfilename, 'error'); + drupal_set_message('Error uploading file : ' . $new_dest_path . '/' . $newuploadfilename, 'error'); } } @@ -467,7 +535,8 @@ color: white; $rows = array(); $header = array( - array('data' => 'Uploaded Date', 'field' => 'ckc.upload_date', 'sort' => 'desc'), + array('data' => 'Sr No.'), + array('data' => 'Uploaded Date'), array('data' => 'File'), array('data' => ''), array('data' => ''), @@ -478,15 +547,15 @@ color: white; $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(); + $result = $query->orderBy('id', 'DESC')->execute(); $number_of_rows = $result->rowCount(); - + $i = 1; while ($row = $result->fetchObject()) { $filearray = explode('.', $row->upload_filename); $filenamewothoutext = $filearray[0]; $filename = $filenamewothoutext; - $item = array(date('d-m-Y', strtotime($row->upload_date)), "<a href='descriptioninfo/{$row->id}' class='autodialog' data-dialog-width='700' title='Click to view file details'>" . $filename . "</a>", + $item = array($i, date('d-m-Y', strtotime($row->upload_date)), "<a href='descriptioninfo/{$row->id}' class='autodialog' data-dialog-width='700' title='Click to view file details'>" . $filename . "</a>", 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'))), @@ -495,25 +564,17 @@ color: white; ); array_push($rows, $item); + $i++; } if ($number_of_rows == 0) { $output .= '<div style="color:red;text-align:center;">No files for convert</div>'; } 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; + $output = theme('table', array( + 'header' => $header, + 'rows' => $rows, + )); } return $output; @@ -541,7 +602,7 @@ function pspice_to_kicad_view() , '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(); + $result = $query->execute(); $number_of_rows = $result->rowCount(); while ($row = $result->fetchObject()) { @@ -586,7 +647,7 @@ function pspice_to_kicad_view() function pspice_to_kicad_download_file() { $id = arg(3); - $root_path = pspice_to_kicad_convert_path(); + $root_path = pspice_to_kicad_directroy_path(); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); @@ -643,8 +704,8 @@ function pspice_to_kicad_convert_file() { try { - $upload_root_path = pspice_to_kicad_upload_path(); - $convert_root_path = pspice_to_kicad_convert_path(); + $upload_root_path = pspice_to_kicad_directroy_path(); + $fileid = arg(3); $query = db_select('custom_kicad_convertor', 'ckc'); @@ -659,19 +720,21 @@ function pspice_to_kicad_convert_file() $filenamearray = explode('.', $row->upload_filepath); $filename = $filenamearray[0]; - $filePath = $upload_root_path . "" . $row->upload_filepath; + $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); + $convert_root_path = get_directory_path($row->uid, $fileid, 2); + $sh_script_file = "/var/www/html/drupal/drupal_7.x/r_fossee_in/sites/all/modules/custom/pspice_to_kicad/convert.sh"; + shell_exec($sh_script_file . " " . $convert_root_path . " " . $filePath . " " . $uploadfolder); $file = $row->upload_filename; $filearray = explode('.', $file); - $converted_file = $convert_root_path . "/" . $filename . ".zip"; - + $converted_file = $convert_root_path . "/" . $filenamewothoutext . ".zip"; + $conv_path = get_directory_path($row->uid, $fileid, 4); $query = db_update('custom_kicad_convertor'); $query->fields(array( 'converted_filename' => $filenamewothoutext . ".zip", - 'converted_filepath' => $filename . ".zip", + 'converted_filepath' => $conv_path . "/" . $filenamewothoutext . ".zip", 'converted_filemime' => file_get_mimetype($converted_file), 'converted_filesize' => filesize($converted_file), 'converted_date' => date("Y-m-d H:i:s"), @@ -687,7 +750,7 @@ function pspice_to_kicad_convert_file() flush(); readfile($converted_file); } catch (Exception $e) { - + var_dump($e);die; 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; @@ -722,7 +785,7 @@ function pspice_to_kicad_convert_approved() $result = $query->execute(); $row = $result->fetchObject(); - $upload_root_path = pspice_to_kicad_upload_path(); + $upload_root_path = pspice_to_kicad_user_upload_path(); $eventfolder = $row->uid; $dest_path = $eventfolder . '/'; $newuploadfilename = $row->upload_filename; @@ -767,7 +830,6 @@ function pspice_to_kicad_convert_upload() $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 = ""; @@ -889,13 +951,16 @@ function pspice_to_kicad_upload_form_submit($form, &$form_state) $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); - } - + get_directory($user->uid, $id); + $new_dest_path = get_directory_path($user->uid, $id, 4); + $get_absolute_path = get_directory_path($user->uid, $id, 2); + + // $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); @@ -903,20 +968,19 @@ function pspice_to_kicad_upload_form_submit($form, &$form_state) /*for uploading*/ if ($newuploadfilename) { - if (file_exists($convert_root_path . $dest_path . $newuploadfilename)) { - unlink($convert_root_path . $dest_path . $newuploadfilename); + if (file_exists($get_absolute_path . '/' . $newuploadfilename)) { + unlink($get_absolute_path . '/' . $newuploadfilename); } /* uploading file */ - if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $convert_root_path . - $dest_path . $newuploadfilename)) { + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $get_absolute_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_filepath" => $new_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"), @@ -928,7 +992,7 @@ function pspice_to_kicad_upload_form_submit($form, &$form_state) drupal_set_message($newuploadfilename . ' uploaded successfully.', 'status'); } else { - drupal_set_message('Error uploading file : ' . $dest_path . $newuploadfilename, 'error'); + drupal_set_message('Error uploading file : ' . $new_dest_path . '/' . $newuploadfilename, 'error'); } } @@ -950,7 +1014,7 @@ function pspice_to_kicad_get_description($file_id = 0) $pdffilearray = explode('@', $row->description_pdf_path); $pdffilenamepath = $pdffilearray[0]; $pdffilearray2 = explode('/', $pdffilenamepath); - $pdffilename = $pdffilearray2[1]; + $pdffilename = $pdffilearray2[3]; $pagecontent .= "<p> <span style='font-weight:bold'>Brief Description of file :</span> " . $row->description . "</p>"; if ($row->description_pdf_path != "" || $row->description_pdf_path != null) { @@ -982,7 +1046,7 @@ function pspice_to_kicad_get_descriptioninfo($file_id = 0) $pdffilearray = explode('@', $row->description_pdf_path); $pdffilenamepath = $pdffilearray[0]; $pdffilearray2 = explode('/', $pdffilenamepath); - $pdffilename = $pdffilearray2[1]; + $pdffilename = $pdffilearray2[3]; $pagecontent .= "<br><p><span style='font-weight:bold'>File name :</span> </b> " . $filename . "</p>"; $pagecontent .= "<p><span style='font-weight:bold'> Author :</span> " . $user_data->name . "</p>"; @@ -1062,7 +1126,7 @@ function pspice_to_kicad_your_uploaded_file() function pspice_to_kicad_download_pdf_file() { $id = arg(3); - $root_path = pspice_to_kicad_upload_path(); + $root_path = pspice_to_kicad_directroy_path(); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); @@ -1074,7 +1138,7 @@ function pspice_to_kicad_download_pdf_file() $pdffilearray = explode('@', $file_data->description_pdf_path); $pdffilenamepath = $pdffilearray[0]; $pdffilearray2 = explode('/', $pdffilenamepath); - $pdffilename = $pdffilearray2[1]; + $pdffilename = $pdffilearray2[3]; header('Content-Type: application/pdf'); header('Content-disposition: attachment; filename="' . $pdffilename . '"'); @@ -1088,7 +1152,7 @@ function pspice_to_kicad_download_pdf_file() function pspice_to_kicad_download_pspice_file() { $id = arg(3); - $root_path = pspice_to_kicad_upload_path(); + $root_path = pspice_to_kicad_directroy_path(); $query = db_select('custom_kicad_convertor'); $query->fields('custom_kicad_convertor'); @@ -1099,11 +1163,10 @@ function pspice_to_kicad_download_pspice_file() 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)); + header('Content-Length: ' . filesize($root_path . '/' . $file_data->upload_filepath)); ob_clean(); flush(); - - readfile($root_path . $file_data->upload_filepath); + readfile($root_path . '/' . $file_data->upload_filepath); } @@ -1192,18 +1255,29 @@ function pspice_to_kicad_delete_file_form_submit($form, &$form_state) $resultcheck = $querycheck->execute(); $row = $resultcheck->fetchObject(); - $upload_root_path = pspice_to_kicad_upload_path(); - $eventfolder = $row->uid; - $dest_path = $eventfolder . '/'; + $upload_root_path = pspice_to_kicad_directroy_path(); $newuploadfilename = $row->upload_filename; - - if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) { - unlink($upload_root_path . $dest_path . $newuploadfilename); + $uploadfilepath = $row->upload_filepath; + $uploadpdfpath = $row->description_pdf_path; + $convertedfilepath = $row->converted_filepath; + if (file_exists($upload_root_path . '/' . $uploadfilepath)) { + unlink($upload_root_path . '/' . $uploadfilepath); } - if (file_exists($upload_root_path . $row->description_pdf_path)) { - unlink($upload_root_path . $row->description_pdf_path); + if (file_exists($upload_root_path . '/' . $uploadpdfpath)) { + unlink($upload_root_path . '/' . $uploadpdfpath); + } + if (file_exists($upload_root_path . '/' . $convertedfilepath)) { + unlink($upload_root_path . '/' . $convertedfilepath); + } + if (!rmdir(get_directory_path($row->uid, $id, 1))) { + drupal_set_message('Could not delete the directory, contact site administrator', 'error'); + } + if (!rmdir(get_directory_path($row->uid, $id, 2))) { + drupal_set_message('Could not delete the directory, contact site administrator', 'error'); + } + if (!rmdir($upload_root_path . '/' . $row->uid . '/' . $id)) { + drupal_set_message('Could not delete the directory, contact site administrator', 'error'); } - //Deleting DB entry of that file. db_delete('custom_kicad_convertor')->condition('id', $row->id)->execute(); @@ -1212,13 +1286,13 @@ function pspice_to_kicad_delete_file_form_submit($form, &$form_state) $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"; + $subject = "[esim.in][PSpice to KiCad Converter] PSpice to KiCad converter: Uploaded schematic/converted 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: +Thank you for using the PSpice to KiCad converter. We have deleted your uploaded schematic/converted file with the following details: Schematic name : " . $row->upload_filename . " |