Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
1867939f
Commit
1867939f
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
forms: Delete instance data when form fields are dropped
parent
1477c9b6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/class.orm.php
+45
-4
45 additions, 4 deletions
include/class.orm.php
include/staff/dynamic-form.inc.php
+45
-13
45 additions, 13 deletions
include/staff/dynamic-form.inc.php
scp/forms.php
+5
-0
5 additions, 0 deletions
scp/forms.php
with
95 additions
and
17 deletions
include/class.orm.php
+
45
−
4
View file @
1867939f
...
@@ -319,6 +319,14 @@ class QuerySet implements IteratorAggregate, ArrayAccess {
...
@@ -319,6 +319,14 @@ class QuerySet implements IteratorAggregate, ArrayAccess {
return
$this
->
count
()
>
0
;
return
$this
->
count
()
>
0
;
}
}
function
delete
()
{
$class
=
$this
->
compiler
;
$compiler
=
new
$class
();
$ex
=
$compiler
->
compileDelete
(
$this
);
$ex
->
execute
();
return
$ex
->
affected_rows
();
}
// IteratorAggregate interface
// IteratorAggregate interface
function
getIterator
()
{
function
getIterator
()
{
$class
=
$this
->
iterator
;
$class
=
$this
->
iterator
;
...
@@ -863,7 +871,28 @@ class MySqlCompiler extends SqlCompiler {
...
@@ -863,7 +871,28 @@ class MySqlCompiler extends SqlCompiler {
function
compileInsert
()
{
function
compileInsert
()
{
}
}
function
compileDelete
()
{
function
compileDelete
(
$queryset
)
{
$model
=
$queryset
->
model
;
$table
=
$model
::
$meta
[
'table'
];
$where_pos
=
array
();
$where_neg
=
array
();
$joins
=
array
();
foreach
(
$queryset
->
constraints
as
$where
)
{
$where_pos
[]
=
$this
->
compileWhere
(
$where
,
$model
);
}
foreach
(
$queryset
->
exclusions
as
$where
)
{
$where_neg
[]
=
$this
->
compileWhere
(
$where
,
$model
);
}
$where
=
''
;
if
(
$where_pos
||
$where_neg
)
{
$where
=
' WHERE '
.
implode
(
' AND '
,
$where_pos
)
.
implode
(
' AND NOT '
,
$where_neg
);
}
$joins
=
$this
->
getJoins
();
$sql
=
'DELETE '
.
$this
->
quote
(
$table
)
.
'.* FROM '
.
$this
->
quote
(
$table
)
.
$joins
.
$where
;
return
new
MysqlExecutor
(
$sql
,
$this
->
params
);
}
}
// Returns meta data about the table used to build queries
// Returns meta data about the table used to build queries
...
@@ -885,14 +914,18 @@ class MysqlExecutor {
...
@@ -885,14 +914,18 @@ class MysqlExecutor {
}
}
function
_prepare
()
{
function
_prepare
()
{
$this
->
execute
();
$this
->
_setup_output
();
$this
->
stmt
->
store_result
();
}
function
execute
()
{
if
(
!
(
$this
->
stmt
=
db_prepare
(
$this
->
sql
)))
if
(
!
(
$this
->
stmt
=
db_prepare
(
$this
->
sql
)))
throw
new
Exception
(
'Unable to prepare query: '
.
db_error
()
throw
new
Exception
(
'Unable to prepare query: '
.
db_error
()
.
' '
.
$this
->
sql
);
.
' '
.
$this
->
sql
);
if
(
count
(
$this
->
params
))
if
(
count
(
$this
->
params
))
$this
->
_bind
(
$this
->
params
);
$this
->
_bind
(
$this
->
params
);
$this
->
stmt
->
execute
();
return
$this
->
stmt
->
execute
();
$this
->
_setup_output
();
$this
->
stmt
->
store_result
();
}
}
function
_bind
(
$params
)
{
function
_bind
(
$params
)
{
...
@@ -997,6 +1030,14 @@ class MysqlExecutor {
...
@@ -997,6 +1030,14 @@ class MysqlExecutor {
$this
->
stmt
=
null
;
$this
->
stmt
=
null
;
}
}
function
affected_rows
()
{
return
$this
->
stmt
->
affected_rows
;
}
function
insert_id
()
{
return
$this
->
stmt
->
insert_id
;
}
function
__toString
()
{
function
__toString
()
{
return
$this
->
sql
;
return
$this
->
sql
;
}
}
...
...
This diff is collapsed.
Click to expand it.
include/staff/dynamic-form.inc.php
+
45
−
13
View file @
1867939f
...
@@ -16,7 +16,7 @@ if($form && $_REQUEST['a']!='add') {
...
@@ -16,7 +16,7 @@ if($form && $_REQUEST['a']!='add') {
$info
=
Format
::
htmlchars
((
$errors
&&
$_POST
)
?
$_POST
:
$info
);
$info
=
Format
::
htmlchars
((
$errors
&&
$_POST
)
?
$_POST
:
$info
);
?>
?>
<form
action=
"?id=
<?php
echo
urlencode
(
$_REQUEST
[
'id'
]);
?>
"
method=
"post"
id=
"save"
>
<form
id=
"manage-form"
action=
"?id=
<?php
echo
urlencode
(
$_REQUEST
[
'id'
]);
?>
"
method=
"post"
>
<?php
csrf_token
();
?>
<?php
csrf_token
();
?>
<input
type=
"hidden"
name=
"do"
value=
"
<?php
echo
$action
;
?>
"
>
<input
type=
"hidden"
name=
"do"
value=
"
<?php
echo
$action
;
?>
"
>
<input
type=
"hidden"
name=
"id"
value=
"
<?php
echo
$info
[
'id'
];
?>
"
>
<input
type=
"hidden"
name=
"id"
value=
"
<?php
echo
$info
[
'id'
];
?>
"
>
...
@@ -167,7 +167,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
...
@@ -167,7 +167,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
if
(
$ferrors
[
'name'
])
echo
'<br/>'
;
echo
$ferrors
[
'name'
];
if
(
$ferrors
[
'name'
])
echo
'<br/>'
;
echo
$ferrors
[
'name'
];
?>
</font>
?>
</font>
</td>
</td>
<td><input
type=
"checkbox"
name=
"delete-
<?php
echo
$id
;
?>
"
<td><input
class=
"delete-box"
type=
"checkbox"
name=
"delete-
<?php
echo
$id
;
?>
"
data-field-label=
"
<?php
echo
$f
->
get
(
'label'
);
?>
"
data-field-id=
"
<?php
echo
$id
;
?>
"
<?php
echo
$deletable
;
?>
/>
<?php
echo
$deletable
;
?>
/>
<input
type=
"hidden"
name=
"sort-
<?php
echo
$id
;
?>
"
<input
type=
"hidden"
name=
"sort-
<?php
echo
$id
;
?>
"
value=
"
<?php
echo
$f
->
get
(
'sort'
);
?>
"
/>
value=
"
<?php
echo
$f
->
get
(
'sort'
);
?>
"
/>
...
@@ -223,32 +225,33 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
...
@@ -223,32 +225,33 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</tr>
</tr>
</tbody>
</tbody>
</table>
</table>
<p
class=
"centered"
id=
"actions"
>
<p
class=
"centered"
>
<input
type=
"submit"
name=
"submit"
value=
"
<?php
echo
$submit_text
;
?>
"
>
<input
type=
"submit"
name=
"submit"
value=
"
<?php
echo
$submit_text
;
?>
"
>
<input
type=
"reset"
name=
"reset"
value=
"Reset"
>
<input
type=
"reset"
name=
"reset"
value=
"Reset"
>
<input
type=
"button"
name=
"cancel"
value=
"Cancel"
onclick=
'window.location.href="?"'
>
<input
type=
"button"
name=
"cancel"
value=
"Cancel"
onclick=
'window.location.href="?"'
>
</p>
</p>
<div
style=
"display:none;"
class=
"dialog"
id=
"confirm
-action
"
>
<div
style=
"display:none;"
class=
"
draggable
dialog"
id=
"
delete-
confirm"
>
<h3><i
class=
"icon-trash"
></i>
Delet
e Existing Data?
</h3>
<h3><i
class=
"icon-trash"
></i>
Remov
e Existing Data?
</h3>
<a
class=
"close"
href=
""
><i
class=
"icon-remove-circle"
></i></a>
<a
class=
"close"
href=
""
><i
class=
"icon-remove-circle"
></i></a>
<hr/>
<hr/>
<p
class=
"confirm-action"
style=
"display:none;"
id=
"submit-confirm"
>
<p>
<strong>
You are about to delete
<span
id=
"deleted-count"
></span>
fields.
</strong>
Would you also like to remove data currently entered for this field?
Would you also like to remove data currently entered for this field?
<em>
If you say no, you will have the option to delete the the data when editing it
</em>
<em>
If you opt not to remove the data now, you will have the option
<br><br>
Deleted data CANNOT be recovered.
to delete the the data when editing it
</em>
<hr>
</p><p
style=
"color:red"
>
<input
type=
"checkbox"
name=
"delete-data"
/>
Deleted data CANNOT be recovered.
Remove all data entered for this field
</p>
</p>
<div>
Please confirm to continue.
</div>
<hr>
<div
id=
"deleted-fields"
></div>
<hr
style=
"margin-top:1em"
/>
<hr
style=
"margin-top:1em"
/>
<p
class=
"full-width"
>
<p
class=
"full-width"
>
<span
class=
"buttons"
style=
"float:left"
>
<span
class=
"buttons"
style=
"float:left"
>
<input
type=
"button"
value=
"No, Cancel"
class=
"close"
>
<input
type=
"button"
value=
"No, Cancel"
class=
"close"
>
</span>
</span>
<span
class=
"buttons"
style=
"float:right"
>
<span
class=
"buttons"
style=
"float:right"
>
<input
type=
"
button
"
value=
"
Save Changes!
"
class=
"confirm"
>
<input
type=
"
submit
"
value=
"
Continue
"
class=
"confirm"
>
</span>
</span>
</p>
</p>
<div
class=
"clear"
></div>
<div
class=
"clear"
></div>
...
@@ -258,3 +261,32 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
...
@@ -258,3 +261,32 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<div
style=
"display:none;"
class=
"dialog draggable"
id=
"field-config"
>
<div
style=
"display:none;"
class=
"dialog draggable"
id=
"field-config"
>
<div
class=
"body"
></div>
<div
class=
"body"
></div>
</div>
</div>
<script
type=
"text/javascript"
>
$
(
'
#manage-form
'
).
on
(
'
submit.inline
'
,
function
()
{
var
formObj
=
this
,
deleted
=
$
(
'
input.delete-box:checked
'
,
this
);
if
(
deleted
.
length
)
{
$
(
'
#overlay
'
).
show
();
$
(
'
#deleted-fields
'
).
empty
();
deleted
.
each
(
function
(
i
,
e
)
{
$
(
'
#deleted-fields
'
).
append
(
$
(
'
<p></p>
'
)
.
append
(
$
(
'
<input/>
'
).
attr
({
type
:
'
checkbox
'
,
name
:
'
delete-data-
'
+
$
(
e
).
data
(
'
fieldId
'
)})
).
append
(
$
(
'
<strong>
'
).
html
(
'
Remove all data entered for <u>
'
+
$
(
e
).
data
(
'
fieldLabel
'
)
+
'
</u>
'
))
);
});
$
(
'
#delete-confirm
'
).
show
().
delegate
(
'
input.confirm
'
,
'
click.confirm
'
,
function
()
{
$
(
'
.dialog#delete-confirm
'
).
hide
();
$
(
formObj
).
unbind
(
'
submit.inline
'
);
$
(
window
).
unbind
(
'
beforeunload
'
);
$
(
'
#loading
'
).
show
();
})
return
false
;
}
// TODO: Popup the 'please wait' dialog
$
(
window
).
unbind
(
'
beforeunload
'
);
$
(
'
#loading
'
).
show
();
});
</script>
This diff is collapsed.
Click to expand it.
scp/forms.php
+
5
−
0
View file @
1867939f
...
@@ -23,6 +23,11 @@ if($_POST) {
...
@@ -23,6 +23,11 @@ if($_POST) {
foreach
(
$form
->
getDynamicFields
()
as
$field
)
{
foreach
(
$form
->
getDynamicFields
()
as
$field
)
{
$id
=
$field
->
get
(
'id'
);
$id
=
$field
->
get
(
'id'
);
if
(
$_POST
[
"delete-
$id
"
]
==
'on'
&&
$field
->
isDeletable
())
{
if
(
$_POST
[
"delete-
$id
"
]
==
'on'
&&
$field
->
isDeletable
())
{
if
(
$_POST
[
"delete-data-
$id
"
])
{
DynamicFormEntryAnswer
::
objects
()
->
filter
(
array
(
'field_id'
=>
$id
))
->
delete
();
}
$field
->
delete
();
$field
->
delete
();
// Don't bother updating the field
// Don't bother updating the field
continue
;
continue
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment