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
mahara
mahara
Commits
fddd13fe
Commit
fddd13fe
authored
Jan 27, 2010
by
Ruslan Kabalin
Committed by
Richard Mansfield
Jan 28, 2010
Browse files
Startdate/stopdate format conversion at view submission stage.
Signed-off-by:
Ruslan Kabalin
<
ruslan.kabalin@luns.net.uk
>
parent
306709b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
htdocs/view/access.php
View file @
fddd13fe
...
...
@@ -251,6 +251,22 @@ if (!function_exists('strptime')) {
}
}
/*
* Converts parsed time array to unix timestamp.
* @param array // date parsed using strptime()
* @return int // Unix timestamp
*/
function
ptimetotime
(
$ptime
)
{
return
mktime
(
$ptime
[
'tm_hour'
],
$ptime
[
'tm_min'
],
$ptime
[
'tm_sec'
],
1
,
$ptime
[
'tm_yday'
]
+
1
,
$ptime
[
'tm_year'
]
+
1900
);
}
function
editaccess_validate
(
Pieform
$form
,
$values
)
{
global
$institution
,
$group
;
if
(
$institution
&&
$values
[
'copynewuser'
]
&&
!
$values
[
'template'
])
{
...
...
@@ -292,30 +308,13 @@ function editaccess_validate(Pieform $form, $values) {
if
(
$item
[
'type'
]
==
'loggedin'
&&
!
$item
[
'startdate'
]
&&
!
$item
[
'stopdate'
])
{
$loggedinaccess
=
true
;
}
if
(
$item
[
'startdate'
]
&&
$item
[
'stopdate'
])
{
$starttime
=
mktime
(
$item
[
'startdate'
][
'tm_hour'
],
$item
[
'startdate'
][
'tm_min'
],
$item
[
'startdate'
][
'tm_sec'
],
1
,
$item
[
'startdate'
][
'tm_yday'
]
+
1
,
$item
[
'startdate'
][
'tm_year'
]
+
1900
);
$stoptime
=
mktime
(
$item
[
'stopdate'
][
'tm_hour'
],
$item
[
'stopdate'
][
'tm_min'
],
$item
[
'stopdate'
][
'tm_sec'
],
1
,
$item
[
'stopdate'
][
'tm_yday'
]
+
1
,
$item
[
'stopdate'
][
'tm_year'
]
+
1900
);
if
(
$starttime
>
$stoptime
)
{
$form
->
set_error
(
'accesslist'
,
get_string
(
'startdatemustbebeforestopdate'
,
'view'
));
break
;
}
if
(
$item
[
'startdate'
]
&&
$item
[
'stopdate'
]
&&
ptimetotime
(
$item
[
'startdate'
])
>
ptimetotime
(
$item
[
'stopdate'
]))
{
$form
->
set_error
(
'accesslist'
,
get_string
(
'startdatemustbebeforestopdate'
,
'view'
));
break
;
}
}
}
// Must have logged in user access for copy new user/group settings.
if
((
$createforgroup
||
(
$institution
&&
$values
[
'copynewuser'
]))
&&
!
$loggedinaccess
)
{
$form
->
set_error
(
'accesslist'
,
get_string
(
'copynewusergroupneedsloggedinaccess'
,
'view'
));
...
...
@@ -345,12 +344,13 @@ function editaccess_submit(Pieform $form, $values) {
}
if
(
$values
[
'accesslist'
])
{
$dateformat
=
get_string
(
'strftimedatetimeshort'
);
foreach
(
$values
[
'accesslist'
]
as
&
$item
)
{
if
(
isset
(
$item
[
'startdate'
]))
{
$item
[
'startdate'
]
=
str
to
time
(
$item
[
'startdate'
]);
$item
[
'startdate'
]
=
ptimetotime
(
str
p
time
(
$item
[
'startdate'
]
,
$dateformat
)
);
}
if
(
isset
(
$item
[
'stopdate'
]))
{
$item
[
'stopdate'
]
=
str
to
time
(
$item
[
'stopdate'
]);
$item
[
'stopdate'
]
=
ptimetotime
(
str
p
time
(
$item
[
'stopdate'
]
,
$dateformat
)
);
}
}
}
...
...
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