Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
legi
soft
gestex
Commits
631fec23
Commit
631fec23
authored
Sep 27, 2020
by
Gabriel Moreau
Browse files
Add get_datasheet_basepath and set_datasheet_new (not easy)
parent
b3eec92b
Changes
1
Hide whitespace changes
Inline
Side-by-side
module/db-functions.php
View file @
631fec23
...
...
@@ -69,6 +69,12 @@ function check_val_in_db($pdo, $table, $col, $value) {
// Datasheet
// ---------------------------------------------------------------------
function
get_datasheet_basepath
{
return
'./data/datasheet'
;
}
// ---------------------------------------------------------------------
function
get_datasheet_listall_by_equipment
(
$pdo
,
$id_equipment
)
{
$sql
=
'SELECT * FROM datasheet WHERE id_equipment = ?;'
;
$stmt
=
$pdo
->
prepare
(
$sql
);
...
...
@@ -87,6 +93,36 @@ function get_datasheet_count_by_equipment($pdo, $id_equipment) {
return
$result_fetch
[
0
][
'count'
];
}
// ---------------------------------------------------------------------
function
set_datasheet_new
(
$pdo
,
$equipment_id
,
$equipment_name
,
$tmp_file
)
{
if
(
!
preg_match
(
'/\.pdf$/i'
,
$tmp_file
))
return
false
;
$new_datasheet_path
=
'./data/datasheet'
;
if
(
!
is_dir
(
$new_datasheet_path
))
mkdir
(
$new_datasheet_path
,
0755
);
$datasheet_filename_kebab
=
string_to_filename_kebab
(
$equipment_name
);
$sql1
=
'INSERT INTO datasheet (description, id_equipment) VALUES (?, ?);'
;
$stmt1
=
$pdo
->
prepare
(
$sql1
);
$stmt1
->
execute
(
array
(
$equipment_name
,
$equipment_id
));
$id_datasheet
=
$pdo
->
lastInsertId
();
$sub_path
=
$id_datasheet
.
'-'
.
random_string
(
8
);
$sql2
=
'UPDATE datasheet SET pathname = ? WHERE id = ?;'
;
$stmt2
=
$pdo
->
prepare
(
$sql2
);
$stmt2
->
execute
(
array
(
$sub_path
.
'/'
.
$datasheet_filename_kebab
.
'.pdf'
,
$id_datasheet
));
$new_dir
=
$new_datasheet_path
.
'/'
.
$sub_path
;
if
(
!
is_dir
(
$new_dir
))
mkdir
(
$new_dir
,
0755
);
move_uploaded_file
(
$tmp_file
,
$new_dir
.
'/'
.
$datasheet_filename_kebab
.
'.pdf'
);
return
$id_datasheet
;
}
// ---------------------------------------------------------------------
// Equipment
// ---------------------------------------------------------------------
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment