summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashantsinalkar2020-06-11 19:53:28 +0530
committerprashantsinalkar2020-06-11 19:53:28 +0530
commitdf6cb3cb75e671c1886b8a41185cfe76d10f9aed (patch)
tree7c32db59fc8898aaee52ac3e2f241296b50fabe1
parent5adca129b3d60f889d019188db32bc3729248899 (diff)
downloadEsim-Pspice-to-kicad-convertor-df6cb3cb75e671c1886b8a41185cfe76d10f9aed.tar.gz
Esim-Pspice-to-kicad-convertor-df6cb3cb75e671c1886b8a41185cfe76d10f9aed.tar.bz2
Esim-Pspice-to-kicad-convertor-df6cb3cb75e671c1886b8a41185cfe76d10f9aed.zip
formatted the code
-rwxr-xr-xconvertfile.inc25
-rwxr-xr-xpspice_to_kicad.module1262
-rwxr-xr-xsettings.inc117
3 files changed, 691 insertions, 713 deletions
diff --git a/convertfile.inc b/convertfile.inc
index 77c239d..a8aed41 100755
--- a/convertfile.inc
+++ b/convertfile.inc
@@ -3,21 +3,20 @@
function pspice_to_kicad_convert_file()
{
-$upload_root_path=pspice_to_kicad_upload_path();
-$convert_root_path=pspice_to_kicad_convert_path();
-$uploadfolder = arg(3);
-$uploadfile=arg(4);
-$filenamearray = explode('.', $uploadfile);
-$filename=$filenamearray[0];
-$filePath=$upload_root_path."".$uploadfolder."/".$uploadfile;
- _convert_run_script($convert_root_path ,$uploadfolder, $filePath ,$filename, $uploadfile);
+ $upload_root_path = pspice_to_kicad_upload_path();
+ $convert_root_path = pspice_to_kicad_convert_path();
+ $uploadfolder = arg(3);
+ $uploadfile = arg(4);
+ $filenamearray = explode('.', $uploadfile);
+ $filename = $filenamearray[0];
+ $filePath = $upload_root_path . "" . $uploadfolder . "/" . $uploadfile;
+ _convert_run_script($convert_root_path, $uploadfolder, $filePath, $filename, $uploadfile);
}
-
-function _convert_run_script($convert_root_path, $uploadfolder ,$filePath, $filename ,$uploadfile)
+function _convert_run_script($convert_root_path, $uploadfolder, $filePath, $filename, $uploadfile)
{
//var_dump($convert_root_path . " " . $uploadfolder . " " . $filePath . " " . $filename." ".$uploadfile);
- $sh_command = "./run.sh " . $convert_root_path. " " . $uploadfolder . " " . $filePath . " " .$filename ." ".$uploadfile;
- exec($sh_command);
-
+ $sh_command = "./run.sh " . $convert_root_path . " " . $uploadfolder . " " . $filePath . " " . $filename . " " . $uploadfile;
+ exec($sh_command);
+
}
diff --git a/pspice_to_kicad.module b/pspice_to_kicad.module
index f44223f..bab44c4 100755
--- a/pspice_to_kicad.module
+++ b/pspice_to_kicad.module
@@ -4,17 +4,17 @@ 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.")
+ "description" => t("Allows users to view converted."),
),
- "manage pspice_to_kicad" => array(
+ "manage pspice_to_kicad" => array(
"title" => t("Upload pspice_to_kicad Files"),
- "description" => t("Allows users to upload files for pspice to kicad convertor.")
+ "description" => t("Allows users to upload files for pspice to kicad convertor."),
),
- "convert pspice_to_kicad" => array(
+ "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.")
+ "description" => t("Allows admin to see files to be convert from pspice to kicad."),
),
-
+
);
}
@@ -25,95 +25,100 @@ function pspice_to_kicad_menu()
"title" => "List of converted files from PSPICE to KICAD",
"page callback" => "pspice_to_kicad_view",
"access arguments" => array(
- "access pspice_to_kicad"
+ "access pspice_to_kicad",
),
- "type" => MENU_CALLBACK
+ "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,
-
- );
+ '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/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"
+ "manage pspice_to_kicad",
),
- "type" => MENU_CALLBACK
+ "type" => MENU_CALLBACK,
);
- $items["pspice-to-kicad/convert"] = array(
+ $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"
+ "convert pspice_to_kicad",
),
- "type" => MENU_CALLBACK
+ "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/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['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/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'
+ 'pspicefile_settings_form',
),
'access arguments' => array(
- 'administer events'
+ 'administer events',
),
'type' => MENU_NORMAL_ITEM,
- 'file' => 'settings.inc'
+ 'file' => 'settings.inc',
);
-
+
return $items;
}
-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_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_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_convert_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'pspice_to_kicad_converts';
}
function pspice_to_kicad_add_form_display()
@@ -124,91 +129,90 @@ function pspice_to_kicad_add_form_display()
return $page_content;
}
-function pspice_to_kicad_add_form($form, &$form_state, $no_js_use = FALSE)
+function pspice_to_kicad_add_form($form, &$form_state, $no_js_use = false)
{
-
+
$form = array();
-
- $form['pspice_files_fieldset'] = array(
- '#type' => 'fieldset',
- '#tree' => TRUE,
- '#prefix' => '<div id="pspice-files-fieldset-wrapper">',
- '#suffix' => '</div>'
+
+ $form['pspice_files_fieldset'] = array(
+ '#type' => 'fieldset',
+ '#tree' => true,
+ '#prefix' => '<div id="pspice-files-fieldset-wrapper">',
+ '#suffix' => '</div>',
+ );
+ if (empty($form_state['num_pspice_files'])) {
+ $form_state['num_pspice_files'] = 1;
+ }
+ $temp = 0;
+ for ($i = 0; $i < $form_state['num_pspice_files']; $i++) {
+ $temp = $i;
+ $form['pspice_files_fieldset'][$i]["div_text"] = array(
+ "#type" => "item",
+ "#markup" => "<label style='color:#1982d1'>" . ($temp + 1) . ". File </label>",
);
- if (empty($form_state['num_pspice_files'])) {
- $form_state['num_pspice_files'] = 1;
- }
- $temp = 0;
- for ($i = 0; $i < $form_state['num_pspice_files']; $i++) {
- $temp = $i;
- $form['pspice_files_fieldset'][$i]["div_text"] = array(
- "#type" => "item",
- "#markup" => "<label style='color:#1982d1'>" . ($temp + 1) . ". File </label>"
- );
- $form['pspice_files_fieldset'][$i]["caption_name"] = array(
- "#type" => "textfield",
- "#title" => "Caption for file",
- '#required' => TRUE,
- "#default_value" => "",
- '#description' => t('<label Style="color:red">Note: Caption will be used as file name after uploading, Give appropriate caption. (Minimum 10 Character)</label>'),
-
- );
- $form['pspice_files_fieldset'][$i]["description"] = array(
- "#type" => "textarea",
- "#required" => TRUE,
- "#title" => "Description",
- '#description' => t('<label>Note: Brief Description about file usage and other important details.(Minimum 50 Character) </label>'),
- );
- $form['pspice_files_fieldset'][$i]['name'] = array(
- '#title' => t('Upload File'),
- '#type' => 'file',
- '#weight' => '5',
- //'#description' => t('Upload File'),
- '#name' => 'files[pspice_files_fieldset_' . $i . '_name]'
- );
+ $form['pspice_files_fieldset'][$i]["caption_name"] = array(
+ "#type" => "textfield",
+ "#title" => "Caption for file",
+ '#required' => true,
+ "#default_value" => "",
+ '#description' => t('<label Style="color:red">Note: Caption will be used as file name after uploading, Give appropriate caption. (Minimum 10 Character)</label>'),
- }
- $form["pspice_files_count"] = array(
- "#type" => "hidden",
- "#value" => $temp
- );
- $form['pspice_files_fieldset']['add_name'] = array(
+ );
+ $form['pspice_files_fieldset'][$i]["description"] = array(
+ "#type" => "textarea",
+ "#required" => true,
+ "#title" => "Description",
+ '#description' => t('<label>Note: Brief Description about file usage and other important details.(Minimum 50 Character) </label>'),
+ );
+ $form['pspice_files_fieldset'][$i]['name'] = array(
+ '#title' => t('Upload File'),
+ '#type' => 'file',
+ '#weight' => '5',
+ //'#description' => t('Upload File'),
+ '#name' => 'files[pspice_files_fieldset_' . $i . '_name]',
+ );
+
+ }
+ $form["pspice_files_count"] = array(
+ "#type" => "hidden",
+ "#value" => $temp,
+ );
+ $form['pspice_files_fieldset']['add_name'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add More File'),
+ '#limit_validation_errors' => array(),
+ '#submit' => array(
+ 'pspice_files_add_more_add_one',
+ ),
+ '#ajax' => array(
+ 'callback' => 'pspice_files_add_more_callback',
+ 'wrapper' => 'pspice-files-fieldset-wrapper',
+ ),
+ );
+ if ($form_state['num_pspice_files'] > 1) {
+ $form['pspice_files_fieldset']['remove_name'] = array(
'#type' => 'submit',
- '#value' => t('Add More File'),
+ '#value' => t('Remove File'),
'#limit_validation_errors' => array(),
'#submit' => array(
- 'pspice_files_add_more_add_one'
+ 'pspice_files_add_more_remove_one',
),
'#ajax' => array(
'callback' => 'pspice_files_add_more_callback',
- 'wrapper' => 'pspice-files-fieldset-wrapper'
- )
+ 'wrapper' => 'pspice-files-fieldset-wrapper',
+ ),
);
- if ($form_state['num_pspice_files'] > 1) {
- $form['pspice_files_fieldset']['remove_name'] = array(
- '#type' => 'submit',
- '#value' => t('Remove File'),
- '#limit_validation_errors' => array(),
- '#submit' => array(
- 'pspice_files_add_more_remove_one'
- ),
- '#ajax' => array(
- 'callback' => 'pspice_files_add_more_callback',
- 'wrapper' => 'pspice-files-fieldset-wrapper'
- )
- );
- }
- if ($no_js_use) {
- if (!empty($form['pspice_files_fieldset']['remove_name']['#ajax'])) {
- unset($form['pspice_files_fieldset']['remove_name']['#ajax']);
- }
- unset($form['pspice_files_fieldset']['add_name']['#ajax']);
+ }
+ if ($no_js_use) {
+ if (!empty($form['pspice_files_fieldset']['remove_name']['#ajax'])) {
+ unset($form['pspice_files_fieldset']['remove_name']['#ajax']);
}
-
-
+ unset($form['pspice_files_fieldset']['add_name']['#ajax']);
+ }
+
$form["submit"] = array(
"#type" => "submit",
- "#value" => "Submit"
+ "#value" => "Submit",
);
return $form;
}
@@ -218,196 +222,195 @@ function pspice_files_add_more_callback($form, $form_state)
return $form['pspice_files_fieldset'];
}
-
function pspice_files_add_more_add_one($form, &$form_state)
{
$form_state['num_pspice_files']++;
- $form_state['rebuild'] = TRUE;
+ $form_state['rebuild'] = true;
//$form_state['no_redirect'] = TRUE;
}
-
function pspice_files_add_more_remove_one($form, &$form_state)
{
if ($form_state['num_pspice_files'] > 1) {
$form_state['num_pspice_files']--;
}
- $form_state['rebuild'] = TRUE;
+ $form_state['rebuild'] = true;
}
-function pspice_to_kicad_add_form_validate(){
-if (isset($_FILES['files'])) {
-
+function pspice_to_kicad_add_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_files_fieldset'))
+ if (strstr($file_form_name, 'pspice_files_fieldset')) {
$file_type = 'P';
+ }
+
switch ($file_type) {
case 'P':
$allowed_extensions_str = variable_get('pspice_files_extensions', '');
break;
}
$allowed_extensions = explode(',', $allowed_extensions_str);
- $allowed_ext=explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $allowed_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
$temp_extension = end($allowed_ext);
-
- if (!in_array($temp_extension, $allowed_extensions))
+
+ 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))
+ }
+
+ 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.'));
-
+ }
+
+ 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;
- /* For checking proper number of files are uploaded*/
- $count=$v["pspice_files_count"]+1;
- $arr=array_values($_FILES['files']['name']);
- for($p = 0; $p < $count; $p++){
- if (strlen(trim($arr[$p]))<=0){
- drupal_set_message('Please upload file to be converted', 'error');
- return;
- }
- }
-
- /*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);
+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;
+ /* For checking proper number of files are uploaded*/
+ $count = $v["pspice_files_count"] + 1;
+ $arr = array_values($_FILES['files']['name']);
+ for ($p = 0; $p < $count; $p++) {
+ if (strlen(trim($arr[$p])) <= 0) {
+ drupal_set_message('Please upload file to be converted', 'error');
+ return;
}
+ }
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
-
- if (strlen(trim($v['pspice_files_fieldset'][$i]["caption_name"])) >=9&&strlen(trim($v['pspice_files_fieldset'][$i]["caption_name"])) <=50) {
+ /*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);
+ }
- if (strlen(trim($v['pspice_files_fieldset'][$i]["description"])) >=49&&strlen(trim($v['pspice_files_fieldset'][$i]["description"])) <=200) {
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ if (strlen(trim($v['pspice_files_fieldset'][$i]["caption_name"])) >= 9 && strlen(trim($v['pspice_files_fieldset'][$i]["caption_name"])) <= 50) {
- $temp = explode(".", $file_name);
- $newuploadfilename = str_replace(' ', '_', trim($v['pspice_files_fieldset'][$i]["caption_name"])). '.' . end($temp);
+ if (strlen(trim($v['pspice_files_fieldset'][$i]["description"])) >= 49 && strlen(trim($v['pspice_files_fieldset'][$i]["description"])) <= 200) {
+ $temp = explode(".", $file_name);
+ $newuploadfilename = str_replace(' ', '_', trim($v['pspice_files_fieldset'][$i]["caption_name"])) . '.' . end($temp);
- /*for uploading*/
- if ($newuploadfilename) {
- if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) {
- drupal_set_message(t("Error uploading file. File !filename already exists. Please give different Caption", array(
- '!filename' => $newuploadfilename
- )), 'error');
- return;
- }
-
- /* uploading file */
-
- if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $upload_root_path .
- $dest_path . $newuploadfilename)) {
- $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" => trim($v['pspice_files_fieldset'][$i]["caption_name"]),
- ":description" => trim($v['pspice_files_fieldset'][$i]["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"),
- ":converted_filename" => "None",
- ":converted_filepath" => "None",
- ":converted_filemime" => "None",
- ":converted_filesize" => 0,
- ":converted_date" => date("Y-m-d"),
- ":converted_flag" => 0,
- ":download_counter" => 0,
-
- );
- /* storing the row id in $result */
- $uploadresult = db_query($uploadquery, $uploadargs, array(
- 'return' => Database::RETURN_INSERT_ID
- ));
- 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 = "Your PSPICE File is received successfully";
-
- $email_body ="
-
-Dear ".$user_data->name.",
+ /*for uploading*/
+ if ($newuploadfilename) {
+ if (file_exists($upload_root_path . $dest_path . $newuploadfilename)) {
+ drupal_set_message(t("Error uploading file. File !filename already exists. Please give different Caption", array(
+ '!filename' => $newuploadfilename,
+ )), 'error');
+ return;
+ }
+
+ /* uploading file */
+
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $upload_root_path .
+ $dest_path . $newuploadfilename)) {
+ $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" => trim($v['pspice_files_fieldset'][$i]["caption_name"]),
+ ":description" => trim($v['pspice_files_fieldset'][$i]["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"),
+ ":converted_filename" => "None",
+ ":converted_filepath" => "None",
+ ":converted_filemime" => "None",
+ ":converted_filesize" => 0,
+ ":converted_date" => date("Y-m-d"),
+ ":converted_flag" => 0,
+ ":download_counter" => 0,
+
+ );
+ /* storing the row id in $result */
+ $uploadresult = db_query($uploadquery, $uploadargs, array(
+ 'return' => Database::RETURN_INSERT_ID,
+ ));
+ 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 = "Your PSPICE File is received successfully";
+
+ $email_body = "
+
+Dear " . $user_data->name . ",
We have received your uploaded pspice file for converting to kicad. Once file is converted we will let you know.
Best Wishes,<br>
-".variable_get('site_name', '')." Team,<br>
+" . variable_get('site_name', '') . " Team,<br>
FOSSEE,IIT Bombay";
-
- send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body ,$from,$bcc,$cc);
+ send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body, $from, $bcc, $cc);
+
+ }
+
+ drupal_set_message($newuploadfilename . ' uploaded successfully.', 'status');
+ } else {
+ drupal_set_message('Error uploading file : ' . $dest_path . $newuploadfilename, 'error');
}
-
-
- drupal_set_message($newuploadfilename . ' uploaded successfully.', 'status');
- } else {
- drupal_set_message('Error uploading file : ' . $dest_path . $newuploadfilename, 'error');
}
- }
-
- }else{
- form_set_error('pspice_files_fieldset_'.$i.'_description', t('Minimum 50 character and Maximum 200 character for description'));
- return;
- }
+ } else {
+
+ form_set_error('pspice_files_fieldset_' . $i . '_description', t('Minimum 50 character and Maximum 200 character for description'));
+ return;
+ }
- }else{
- form_set_error('pspice_files_fieldset_'.$i.'_caption_name', t('Minimum 10 character and Maximum 50 character for caption'));
- return;
- }
+ } else {
+ form_set_error('pspice_files_fieldset_' . $i . '_caption_name', t('Minimum 10 character and Maximum 50 character for caption'));
+ return;
+ }
-
-
-$i++;
-}
+ $i++;
+ }
}
+function pspice_to_kicad_remain_list()
+{
-function pspice_to_kicad_remain_list(){
-
-$convertor_CSS="
+ $convertor_CSS = "
.convert_button {
display: block;
width: 80px;
@@ -420,70 +423,63 @@ color: white;
}
";
- drupal_add_css($convertor_CSS, 'inline', 'header');
-
-
- $caption="<h4>List of files to be converted: <br><br><h4>";
- $output="";
- $query = "";
- $count_query = "";
- $rows=array();
-
- $header = array(
- array('data'=>'Caption', 'field'=>'ckc.caption'),
- array('data'=>'Uploaded Date', 'field'=>'ckc.upload_date', 'sort'=>'desc'),
- array('data'=>'filename', 'field'=>'ckc.upload_filename'),
- array('data'=>''),
- array('data'=>''),
- array('data'=>''),
- );
-
-
-
- $query = db_select('custom_kicad_convertor', 'ckc');
- $query->fields('ckc', array('id','uid','caption', '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()) {
- $item = array($row->caption, $row->upload_date, $row->upload_filename,
- l(t('Convert'), '/pspice-to-kicad/convert/file/'.$row->id, array('attributes' =>
- array('class' => array('convert_button')))),
- l(t('Upload'), '/pspice-to-kicad/convert/upload/'.$row->id, array('attributes' =>
- array('class' => array('convert_button')))),
- l(t('Published'), '/pspice-to-kicad/convert/approved/'.$row->id, array('attributes' =>
- array('class' => array('convert_button')))),
-
- );
- array_push($rows, $item);
- }
-
- 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;
- }
-
- return $output;
- }
-
-
-function pspice_to_kicad_view(){
+ drupal_add_css($convertor_CSS, 'inline', 'header');
+
+ $caption = "<h4>List of files to be converted: <br><br><h4>";
+ $output = "";
+ $query = "";
+ $count_query = "";
+ $rows = array();
+
+ $header = array(
+ array('data' => 'Caption', 'field' => 'ckc.caption'),
+ array('data' => 'Uploaded Date', 'field' => 'ckc.upload_date', 'sort' => 'desc'),
+ array('data' => 'filename', 'field' => 'ckc.upload_filename'),
+ array('data' => ''),
+ array('data' => ''),
+ array('data' => ''),
+ );
+
+ $query = db_select('custom_kicad_convertor', 'ckc');
+ $query->fields('ckc', array('id', 'uid', 'caption', '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()) {
+ $item = array($row->caption, $row->upload_date, $row->upload_filename,
+ l(t('Convert'), '/pspice-to-kicad/convert/file/' . $row->id, array('attributes' => array('class' => array('convert_button')))),
+ l(t('Upload'), '/pspice-to-kicad/convert/upload/' . $row->id, array('attributes' => array('class' => array('convert_button')))),
+ l(t('Published'), '/pspice-to-kicad/convert/approved/' . $row->id, array('attributes' => array('class' => array('convert_button')))),
+
+ );
+ array_push($rows, $item);
+ }
+
+ 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;
+ }
+
+ return $output;
+}
+
+function pspice_to_kicad_view()
+{
/*$convertor_CSS="
.convert_button {
@@ -498,388 +494,372 @@ color: white;
}
";
- drupal_add_css($convertor_CSS, 'inline', 'header');
-*/
-
- $caption="<h4>List of Converted files: <br><br><h4>";
- $output="";
- $query = "";
- $count_query = "";
- $rows=array();
-
- $header = array(
- array('data'=>'Description', 'field'=>'ckc.description'),
- array('data'=>'Date', 'field'=>'ckc.converted_date', 'sort'=>'desc'),
- array('data'=>'Download'),
-
- );
-
- $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);
- $result = $query->extend('PagerDefault')->limit(10)->extend('TableSort')->orderByHeader($header)->execute();
- $number_of_rows = $result->rowCount();
-
-
- while ($row = $result->fetchObject()) {
- $item = array($row->description, $row->converted_date,
- l($row->converted_filename, '/pspice-to-kicad/download/file/' . $row->id),
- /*"<a href=".$GLOBALS['base_url']."pspice-to-kicad/download/file/".$row->id." title='Click to convert'>".$row->converted_filename."</a>",*/
-
- );
- array_push($rows, $item);
- }
-
- if ($number_of_rows==0) {
- $output .= '<div style="color:red;text-align:center;">No files available yet for download</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;
- }
-
- return $output;
+drupal_add_css($convertor_CSS, 'inline', 'header');
+ */
-}
+ $caption = "<h4>List of Converted files: <br><br><h4>";
+ $output = "";
+ $query = "";
+ $count_query = "";
+ $rows = array();
+ $header = array(
+ array('data' => 'Description', 'field' => 'ckc.description'),
+ array('data' => 'Date', 'field' => 'ckc.converted_date', 'sort' => 'desc'),
+ array('data' => 'Download'),
+ );
-function pspice_to_kicad_download_file()
-{
- $id = arg(3);
- $root_path = pspice_to_kicad_convert_path();
-
- // $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE id = %d LIMIT 1", $solution_file_id);
- $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));
- readfile($root_path ."/". $file_data->converted_filepath);
-
-}
+ $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);
+ $result = $query->extend('PagerDefault')->limit(10)->extend('TableSort')->orderByHeader($header)->execute();
+ $number_of_rows = $result->rowCount();
+
+ while ($row = $result->fetchObject()) {
+ $item = array($row->description, $row->converted_date,
+ l($row->converted_filename, '/pspice-to-kicad/download/file/' . $row->id),
+ /*"<a href=".$GLOBALS['base_url']."pspice-to-kicad/download/file/".$row->id." title='Click to convert'>".$row->converted_filename."</a>",*/
-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,
+ );
+ array_push($rows, $item);
+ }
+
+ if ($number_of_rows == 0) {
+ $output .= '<div style="color:red;text-align:center;">No files available yet for download</div>';
+ } else {
+
+ $build['pager_table'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ '#caption' => $caption,
+ '#attributes' => array(
+ 'class' => array('table table-bordered table-hover'),
),
);
- $system = drupal_mail_system($my_module, $my_mail_token);
- $message = $system->format($message);
- if ($system->mail($message)) {
- return TRUE;
- }
- else {
- return FALSE;
- }
+
+ // Attach the pager theme.
+ $build['pager_pager'] = array('#theme' => 'pager');
+ $output = $build;
}
-function pspice_to_kicad_convert_file()
+ return $output;
+
+}
+
+function pspice_to_kicad_download_file()
{
-$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("/var/www/html/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"),
- 'converted_flag' => "1",
- ));
- $query->condition('id', $row->id);
- $result = $query->execute();
+ $id = arg(3);
+ $root_path = pspice_to_kicad_convert_path();
+
+ // $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE id = %d LIMIT 1", $solution_file_id);
+ $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));
+ 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;
+ }
+}
- header('Content-Type: ' . file_get_mimetype($converted_file));
- header('Content-disposition: attachment; filename="'.$filenamewothoutext.".zip".'"');
- header('Content-Length: ' . filesize($converted_file));
- readfile($converted_file);
+function pspice_to_kicad_convert_file()
+{
+ $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("/var/www/html/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"),
+ '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));
+ readfile($converted_file);
}
function pspice_to_kicad_convert_approved()
{
-$fileid = arg(3);
+ $fileid = arg(3);
+
+ $query = db_update('custom_kicad_convertor');
+ $query->fields(array(
+ 'converted_flag' => "2",
+ ));
+ $query->condition('id', $fileid);
+ $result = $query->execute();
+ if ($result) {
- $query = db_update('custom_kicad_convertor');
- $query->fields(array(
- 'converted_flag' => "2",
- ));
+ $query = db_select('custom_kicad_convertor');
+ $query->fields('custom_kicad_convertor');
$query->condition('id', $fileid);
$result = $query->execute();
- if($result){
+ $row = $result->fetchObject();
- $query = db_select('custom_kicad_convertor');
- $query->fields('custom_kicad_convertor');
- $query->condition('id', $fileid);
- $result = $query->execute();
- $row = $result->fetchObject();
+ $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 = "Your PSPICE file is successfully converted";
- $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 = "Your PSPICE file is successfully converted";
-
- $email_body = "
+ $email_body = "
-Dear ".$user_data->name.",
+Dear " . $user_data->name . ",
Your uploaded file is converted to kicad and can be download now.
Best Wishes,<br>
-".variable_get('site_name', '')." Team,<br>
+" . variable_get('site_name', '') . " Team,<br>
FOSSEE,IIT Bombay";
-
- send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body,$from,$bcc,$cc);
- }
- drupal_goto("pspice-to-kicad/convert");
- return;
-}
+ send_mail(variable_get('kicad_from_email', ''), $to, $subject, $email_body, $from, $bcc, $cc);
+ }
+ drupal_goto("pspice-to-kicad/convert");
+ return;
+}
function pspice_to_kicad_convert_upload()
{
-$fileid = arg(3);
-
+ $fileid = arg(3);
$page_content = "";
- $pspice_to_kicad_upload_form = drupal_get_form("pspice_to_kicad_upload_form",$fileid);
+ $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;
-
}
-
-function pspice_to_kicad_upload_form($form, &$form_state,$fileid)
+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' => '<div id="pspice-files-fieldset-wrapper">',
- '#suffix' => '</div>'
- );
-
- $form['pspice_uploadfiles_fieldset']["file_caption_name"] = array(
- "#type" => "textfield",
- "#title" => "Caption for file",
- "#default_value" => $row->caption,
- '#attributes' => array('readonly' => 'readonly'),
- '#disabled' => TRUE,
- '#description' => t('<label Style="color:red">Note: Caption is non editable </label>'),
-
- );
- $form['pspice_uploadfiles_fieldset']["file_description"] = array(
- "#type" => "textarea",
- "#default_value" => $row->description,
- "#title" => "Description",
- '#attributes' => array('readonly' => 'readonly'),
- '#disabled' => TRUE,
- '#description' => t('<label Style="color:red">Note: Description is non editable </label>'),
- );
-
- $form['pspice_uploadfiles_fieldset']['name'] = array(
- '#title' => t('Upload File'),
- '#type' => 'file',
- '#weight' => '5',
- );
- $form["pspice_files_id"] = array(
- "#type" => "hidden",
- "#value" => $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' => '<div id="pspice-files-fieldset-wrapper">',
+ '#suffix' => '</div>',
+ );
+
+ $form['pspice_uploadfiles_fieldset']["file_caption_name"] = array(
+ "#type" => "textfield",
+ "#title" => "Caption for file",
+ "#default_value" => $row->caption,
+ '#attributes' => array('readonly' => 'readonly'),
+ '#disabled' => true,
+ '#description' => t('<label Style="color:red">Note: Caption is non editable </label>'),
+
+ );
+ $form['pspice_uploadfiles_fieldset']["file_description"] = array(
+ "#type" => "textarea",
+ "#default_value" => $row->description,
+ "#title" => "Description",
+ '#attributes' => array('readonly' => 'readonly'),
+ '#disabled' => true,
+ '#description' => t('<label Style="color:red">Note: Description is non editable </label>'),
+ );
+
+ $form['pspice_uploadfiles_fieldset']['name'] = array(
+ '#title' => t('Upload File'),
+ '#type' => 'file',
+ '#weight' => '5',
+ );
+ $form["pspice_files_id"] = array(
+ "#type" => "hidden",
+ "#value" => $fileid,
+ );
$form["submit"] = array(
"#type" => "submit",
- "#value" => "Submit"
+ "#value" => "Submit",
);
return $form;
}
-
-
-function pspice_to_kicad_upload_form_validate(){
-if (isset($_FILES['files'])) {
-
+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'))
+ 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]));
+ $allowed_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
$temp_extension = end($allowed_ext);
-
- if (!in_array($temp_extension, $allowed_extensions))
+
+ 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))
+ }
+
+ 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.'));
-
+ }
+
+ 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)
+{
-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 upload file to be converted', '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);
- }
+ 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 upload file to be converted', 'error');
+ return;
+ }
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ $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);
+ }
- $temp = explode(".", $file_name);
- $newuploadfilename = str_replace(' ', '_', trim($v['pspice_uploadfiles_fieldset']["file_caption_name"])). '.' . end($temp);
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ $temp = explode(".", $file_name);
+ $newuploadfilename = str_replace(' ', '_', trim($v['pspice_uploadfiles_fieldset']["file_caption_name"])) . '.' . end($temp);
- /*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(
-
- "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"),
- "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');
- }
+ /*for uploading*/
+ if ($newuploadfilename) {
+ if (file_exists($convert_root_path . $dest_path . $newuploadfilename)) {
+ unlink($convert_root_path . $dest_path . $newuploadfilename);
}
-
-
-
-
-
+ /* uploading file */
-}
-drupal_goto("pspice-to-kicad/convert");
- return;
-}
+ 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(
+
+ "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"),
+ "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;
+}
diff --git a/settings.inc b/settings.inc
index 73c68fd..60a6eed 100755
--- a/settings.inc
+++ b/settings.inc
@@ -3,73 +3,72 @@
function pspicefile_settings_form($form_state)
{
- $form['emails'] = array(
- '#type' => 'textfield',
- '#title' => t('(Bcc) Notification emails'),
- '#description' => t('Specify emails id for Bcc option of mail system with comma separated'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('kicad_emails', ''),
- );
-
- $form['cc_emails'] = array(
- '#type' => 'textfield',
- '#title' => t('(Cc) Notification emails'),
- '#description' => t('Specify emails id for Cc option of mail system with comma separated'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('kicad_cc_emails', ''),
- );
-
- $form['from_email'] = array(
- '#type' => 'textfield',
- '#title' => t('Outgoing from email address'),
- '#description' => t('Email address to be display in the from field of all outgoing messages'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('kicad_from_email', ''),
- );
- $form['extensions']['pspicefile'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed pspice file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('pspice_files_extensions', ''),
- );
- $form['extensions']['kicadcorrectedfile'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed Kicad corrected file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('kicad_corrected_files_extensions', ''),
- );
+ $form['emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Bcc) Notification emails'),
+ '#description' => t('Specify emails id for Bcc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => true,
+ '#default_value' => variable_get('kicad_emails', ''),
+ );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- return $form;
+ $form['cc_emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Cc) Notification emails'),
+ '#description' => t('Specify emails id for Cc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => true,
+ '#default_value' => variable_get('kicad_cc_emails', ''),
+ );
+
+ $form['from_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Outgoing from email address'),
+ '#description' => t('Email address to be display in the from field of all outgoing messages'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => true,
+ '#default_value' => variable_get('kicad_from_email', ''),
+ );
+ $form['extensions']['pspicefile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed pspice file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => true,
+ '#default_value' => variable_get('pspice_files_extensions', ''),
+ );
+ $form['extensions']['kicadcorrectedfile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed Kicad corrected file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => true,
+ '#default_value' => variable_get('kicad_corrected_files_extensions', ''),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+ return $form;
}
function pspicefile_settings_form_validate($form, &$form_state)
{
- return;
+ return;
}
function pspicefile_settings_form_submit($form, &$form_state)
{
- variable_set('kicad_emails', $form_state['values']['emails']);
- variable_set('kicad_cc_emails', $form_state['values']['cc_emails']);
- variable_set('kicad_from_email', $form_state['values']['from_email']);
- variable_set('pspice_files_extensions', $form_state['values']['pspicefile']);
+ variable_set('kicad_emails', $form_state['values']['emails']);
+ variable_set('kicad_cc_emails', $form_state['values']['cc_emails']);
+ variable_set('kicad_from_email', $form_state['values']['from_email']);
+ variable_set('pspice_files_extensions', $form_state['values']['pspicefile']);
variable_set('kicad_corrected_files_extensions', $form_state['values']['kicadcorrectedfile']);
- drupal_set_message(t('Settings updated'), 'status');
+ drupal_set_message(t('Settings updated'), 'status');
}
-