Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Branches containing commit
No related tags found
Tags containing commit
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 {
return
$this
->
count
()
>
0
;
}
function
delete
()
{
$class
=
$this
->
compiler
;
$compiler
=
new
$class
();
$ex
=
$compiler
->
compileDelete
(
$this
);
$ex
->
execute
();
return
$ex
->
affected_rows
();
}
// IteratorAggregate interface
function
getIterator
()
{
$class
=
$this
->
iterator
;
...
...
@@ -863,7 +871,28 @@ class MySqlCompiler extends SqlCompiler {
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
...
...
@@ -885,14 +914,18 @@ class MysqlExecutor {
}
function
_prepare
()
{
$this
->
execute
();
$this
->
_setup_output
();
$this
->
stmt
->
store_result
();
}
function
execute
()
{
if
(
!
(
$this
->
stmt
=
db_prepare
(
$this
->
sql
)))
throw
new
Exception
(
'Unable to prepare query: '
.
db_error
()
.
' '
.
$this
->
sql
);
if
(
count
(
$this
->
params
))
$this
->
_bind
(
$this
->
params
);
$this
->
stmt
->
execute
();
$this
->
_setup_output
();
$this
->
stmt
->
store_result
();
return
$this
->
stmt
->
execute
();
}
function
_bind
(
$params
)
{
...
...
@@ -997,6 +1030,14 @@ class MysqlExecutor {
$this
->
stmt
=
null
;
}
function
affected_rows
()
{
return
$this
->
stmt
->
affected_rows
;
}
function
insert_id
()
{
return
$this
->
stmt
->
insert_id
;
}
function
__toString
()
{
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') {
$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
();
?>
<input
type=
"hidden"
name=
"do"
value=
"
<?php
echo
$action
;
?>
"
>
<input
type=
"hidden"
name=
"id"
value=
"
<?php
echo
$info
[
'id'
];
?>
"
>
...
...
@@ -167,7 +167,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
if
(
$ferrors
[
'name'
])
echo
'<br/>'
;
echo
$ferrors
[
'name'
];
?>
</font>
</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
;
?>
/>
<input
type=
"hidden"
name=
"sort-
<?php
echo
$id
;
?>
"
value=
"
<?php
echo
$f
->
get
(
'sort'
);
?>
"
/>
...
...
@@ -223,32 +225,33 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</tr>
</tbody>
</table>
<p
class=
"centered"
id=
"actions"
>
<p
class=
"centered"
>
<input
type=
"submit"
name=
"submit"
value=
"
<?php
echo
$submit_text
;
?>
"
>
<input
type=
"reset"
name=
"reset"
value=
"Reset"
>
<input
type=
"button"
name=
"cancel"
value=
"Cancel"
onclick=
'window.location.href="?"'
>
</p>
<div
style=
"display:none;"
class=
"dialog"
id=
"confirm
-action
"
>
<h3><i
class=
"icon-trash"
></i>
Delet
e Existing Data?
</h3>
<div
style=
"display:none;"
class=
"
draggable
dialog"
id=
"
delete-
confirm"
>
<h3><i
class=
"icon-trash"
></i>
Remov
e Existing Data?
</h3>
<a
class=
"close"
href=
""
><i
class=
"icon-remove-circle"
></i></a>
<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?
<em>
If you say no, you will have the option to delete the the data when editing it
</em>
<br><br>
Deleted data CANNOT be recovered.
<hr>
<input
type=
"checkbox"
name=
"delete-data"
/>
Remove all data entered for this field
<em>
If you opt not to remove the data now, you will have the option
to delete the the data when editing it
</em>
</p><p
style=
"color:red"
>
Deleted data CANNOT be recovered.
</p>
<div>
Please confirm to continue.
</div>
<hr>
<div
id=
"deleted-fields"
></div>
<hr
style=
"margin-top:1em"
/>
<p
class=
"full-width"
>
<span
class=
"buttons"
style=
"float:left"
>
<input
type=
"button"
value=
"No, Cancel"
class=
"close"
>
</span>
<span
class=
"buttons"
style=
"float:right"
>
<input
type=
"
button
"
value=
"
Save Changes!
"
class=
"confirm"
>
<input
type=
"
submit
"
value=
"
Continue
"
class=
"confirm"
>
</span>
</p>
<div
class=
"clear"
></div>
...
...
@@ -258,3 +261,32 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<div
style=
"display:none;"
class=
"dialog draggable"
id=
"field-config"
>
<div
class=
"body"
></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) {
foreach
(
$form
->
getDynamicFields
()
as
$field
)
{
$id
=
$field
->
get
(
'id'
);
if
(
$_POST
[
"delete-
$id
"
]
==
'on'
&&
$field
->
isDeletable
())
{
if
(
$_POST
[
"delete-data-
$id
"
])
{
DynamicFormEntryAnswer
::
objects
()
->
filter
(
array
(
'field_id'
=>
$id
))
->
delete
();
}
$field
->
delete
();
// Don't bother updating the field
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