Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
timesheet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web2project
timesheet
Commits
8f431fdf
Commit
8f431fdf
authored
Jan 16, 2014
by
Jean-Paul Saman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configuration and upgrade.
parent
620d5a39
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
238 additions
and
188 deletions
+238
-188
configure.php
configure.php
+112
-145
setup.php
setup.php
+126
-43
No files found.
configure.php
View file @
8f431fdf
...
...
@@ -2,14 +2,14 @@
/*
* Name: Timesheet
* Directory: timesheet
* Version:
1.0.3
* Version:
2.0.
* Type: user
* UI Name: Timesheet
* UI Icon: timesheet.png
*/
/*
* Copyright (C) 2007
, M2X
* Copyright (C) 2007
-2014, M2X BV
*
* Authors: Jean-Paul Saman
*
...
...
@@ -30,19 +30,68 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
// Deny all but system admins
if
(
getDenyEdit
(
'system'
))
{
$AppUI
->
redirect
(
"m=public&a=access_denied"
);
if
(
!
defined
(
'W2P_BASE_DIR'
))
{
die
(
'You should not access this file directly.'
);
}
@
include_once
(
"./functions/admin_func.php"
);
$CONFIG_FILE
=
"./modules/timesheet/config.php"
;
// deny all but system admins
$canEdit
=
canEdit
(
'system'
);
if
(
!
$canEdit
)
{
$AppUI
->
redirect
(
ACCESS_DENIED
);
}
$AppUI
->
savePlace
();
// Pull all users
$q
=
new
DBQuery
();
// TODO Remove queries from this file
$config
=
array
();
$q
=
new
w2p_Database_Query
;
if
(
isset
(
$_POST
[
'forcesubmit'
])
&&
isset
(
$_POST
[
'submit'
]))
{
$q
->
addTable
(
'timesheet_config'
);
$q
->
addUpdate
(
'timesheet_config'
,
'timesheet_approval_by'
);
$q
->
addUpdate
(
'timesheet_value'
,
$_POST
[
'timesheet_approval_by'
]);
$q
->
addWhere
(
'timesheet_config = "timesheet_approval_by"'
);
if
(
!
$q
->
exec
())
{
$AppUI
->
setMsg
(
db_error
(),
UI_MSG_ERROR
);
}
$q
->
clear
();
$q
->
addTable
(
'timesheet_config'
);
$q
->
addUpdate
(
'timesheet_config'
,
'timesheet_book_year'
);
$q
->
addUpdate
(
'timesheet_value'
,
$_POST
[
'timesheet_book_year'
]);
$q
->
addWhere
(
'timesheet_config = "timesheet_book_year"'
);
if
(
!
$q
->
exec
())
{
$AppUI
->
setMsg
(
db_error
(),
UI_MSG_ERROR
);
}
$q
->
clear
();
$q
->
addTable
(
'timesheet_config'
);
$q
->
addUpdate
(
'timesheet_config'
,
'timesheet_sort_order'
);
$q
->
addUpdate
(
'timesheet_value'
,
$_POST
[
'timesheet_sort_order'
]);
$q
->
addWhere
(
'timesheet_config = "timesheet_sort_order"'
);
if
(
!
$q
->
exec
())
{
$AppUI
->
setMsg
(
db_error
(),
UI_MSG_ERROR
);
}
else
{
$AppUI
->
setMsg
(
'Timesheet configuration saved'
,
UI_MSG_OK
);
}
$q
->
clear
();
$AppUI
->
redirect
(
'm=timesheet&a=configure'
);
}
else
{
// Read values from table
$q
->
addQuery
(
'*'
);
$q
->
addTable
(
'timesheet_config'
);
if
(
!
$q
->
exec
())
{
$AppUI
->
setMsg
(
db_error
(),
UI_MSG_ERROR
);
}
else
{
$AppUI
->
setMsg
(
'Timesheet configuration read'
,
UI_MSG_OK
);
}
while
(
$row
=
$q
->
fetchRow
())
{
$config
[
$row
[
'timesheet_config'
]]
=
$row
[
'timesheet_value'
];
}
$q
->
clear
();
}
// Get list of all users
$q
->
addQuery
(
'user_id, contact_first_name, contact_last_name'
);
$q
->
addTable
(
'users'
);
$q
->
addTable
(
'contacts'
);
...
...
@@ -53,152 +102,70 @@ $users = array();
while
(
$row
=
$q
->
fetchRow
())
{
$users
[
$row
[
'user_id'
]]
=
$row
[
'contact_last_name'
]
.
', '
.
$row
[
'contact_first_name'
];
}
$q
->
clear
();
/* Sort order */
$order
=
array
();
$order
[
0
]
=
"Ascending"
;
$order
[
1
]
=
"Descending"
;
/* All config options, their descriptions and their default values are defined
* here. Add new config options here. Type can be "checkbox", "text", "radio" or
* "select". If the type is "radio," it must include a set of buttons. If it's
* "select" then be sure to include a 'list' entry with the options. if the key
* starts with headingXXX then it will just display the contents on the value.
* This is used for grouping.
*/
$config_options
=
array
(
"heading1"
=>
$AppUI
->
_
(
'Timesheet rights'
),
"approval_by"
=>
array
(
"description"
=>
$AppUI
->
_
(
'Approval by'
),
"value"
=>
''
,
'type'
=>
'select'
,
'list'
=>
$users
),
"book_year"
=>
array
(
"description"
=>
$AppUI
->
_
(
'Book year'
),
"value"
=>
''
,
"type"
=>
'text'
),
"sort_order"
=>
array
(
"description"
=>
$AppUI
->
_
(
'Sort order'
),
"value"
=>
''
,
'type'
=>
'select'
,
'list'
=>
$order
)
);
//if this is a submitted page, overwrite the config file.
if
(
dPgetParam
(
$_POST
,
"Save"
,
''
)
!=
''
)
{
if
(
is_writable
(
$CONFIG_FILE
))
{
if
(
!
$handle
=
fopen
(
$CONFIG_FILE
,
'w'
))
{
$AppUI
->
setMsg
(
$CONFIG_FILE
.
" "
.
$AppUI
->
_
(
'cannot be opened'
),
UI_MSG_ERROR
);
exit
;
}
if
(
fwrite
(
$handle
,
"<?php //Do not edit this file by hand, it will be overwritten by the configuration utility.
\n
"
)
===
FALSE
)
{
$AppUI
->
setMsg
(
$CONFIG_FILE
.
" "
.
$AppUI
->
_
(
'cannot be written to'
),
UI_MSG_ERROR
);
exit
;
}
else
{
foreach
(
$config_options
as
$key
=>
$value
){
if
(
substr
(
$key
,
0
,
7
)
==
'heading'
)
continue
;
$val
=
""
;
switch
(
$value
[
'type'
]){
case
'checkbox'
:
$val
=
isset
(
$_POST
[
$key
])
?
"1"
:
"0"
;
break
;
case
'text'
:
$val
=
isset
(
$_POST
[
$key
])
?
$_POST
[
$key
]
:
""
;
break
;
case
'select'
:
$val
=
isset
(
$_POST
[
$key
])
?
$_POST
[
$key
]
:
"0"
;
break
;
case
'radio'
:
$val
=
$_POST
[
$key
];
break
;
default
:
break
;
}
fwrite
(
$handle
,
"
\$
TIMESHEET_CONFIG['"
.
$key
.
"'] = '"
.
$val
.
"';
\n
"
);
}
fwrite
(
$handle
,
"?>
\n
"
);
$AppUI
->
setMsg
(
$CONFIG_FILE
.
" "
.
$AppUI
->
_
(
'has been successfully updated'
),
UI_MSG_OK
);
fclose
(
$handle
);
require
(
$CONFIG_FILE
);
}
}
else
{
$AppUI
->
setMsg
(
$CONFIG_FILE
.
" "
.
$AppUI
->
_
(
'is not writable'
),
UI_MSG_ERROR
);
}
}
else
if
(
dPgetParam
(
$_POST
,
$AppUI
->
_
(
'cancel'
),
''
)
!=
''
){
$AppUI
->
redirect
(
"m=system&a=viewmods"
);
}
//$TIMESHEET_CONFIG = array();
require_once
(
$CONFIG_FILE
);
//Read the current config values from the config file and update the array.
foreach
(
$config_options
as
$key
=>
$value
){
if
(
isset
(
$TIMESHEET_CONFIG
[
$key
])){
$config_options
[
$key
][
'value'
]
=
$TIMESHEET_CONFIG
[
$key
];
}
}
// setup the title block
$titleBlock
=
new
CTitleBlock
(
'Configure Timesheet Module'
,
'timesheet.png'
,
$m
,
"
$m
.
$a
"
);
$titleBlock
->
addCrumb
(
"?m=system"
,
"
System A
dmin"
);
$titleBlock
->
addCrumb
(
"?m=system&a=viewmods"
,
"
Modules
"
);
$titleBlock
=
new
w2p_Theme_TitleBlock
(
'Configure Timesheet Module'
,
'timesheet.png'
,
$m
,
'$m'
.
'.'
.
'$a'
);
$titleBlock
->
addCrumb
(
"?m=system"
,
"
system a
dmin"
);
$titleBlock
->
addCrumb
(
"?m=system&a=viewmods"
,
"
modules list
"
);
$titleBlock
->
show
();
?>
<script
language=
"javascript"
type=
"text/javascript"
>
function
submitFrm
(
frmName
)
{
eval
(
'
document.
'
+
frmName
+
'
.submit();
'
);
}
</script>
<form
method=
"post"
>
<form
name=
"frmTimesheetConfig"
method=
"post"
accept-charset=
"utf-8"
>
<input
type=
"hidden"
name=
"forcesubmit"
value=
"true"
/>
<table
class=
"std"
>
<?php
foreach
(
$config_options
as
$key
=>
$value
){
?>
<tr>
<?php
// the key starts with hr, then just display the value
if
(
substr
(
$key
,
0
,
7
)
==
'heading'
){
?>
<th
align=
"center"
colspan=
"2"
>
<?php
echo
$value
?>
</th>
<?php
}
else
{
?>
<td
align=
"right"
>
<?php
echo
$value
[
'description'
]
?>
</td>
<td>
<?php
switch
(
$value
[
'type'
]){
case
'checkbox'
:
?>
<input
type=
"checkbox"
name=
"
<?php
echo
$key
?>
"
<?php
echo
$value
[
'value'
]
?
"checked=
\"
checked
\"
"
:
""
?>
>
<?php
break
;
case
'text'
:
?>
<input
type=
"text"
name=
"
<?php
echo
$key
?>
"
value=
"
<?php
echo
$value
[
'value'
]
?>
"
>
<?php
break
;
case
'select'
:
print
arraySelect
(
$value
[
"list"
],
$key
,
'class="text" size="1" id="'
.
$key
.
'" '
.
$value
[
"events"
],
$value
[
"value"
]
);
break
;
case
'radio'
:
foreach
(
$value
[
'buttons'
]
as
$v
=>
$n
)
{
?>
<label><input
type=
"radio"
name=
"
<?php
echo
$key
;
?>
"
id=
"
<?php
echo
$key
;
?>
"
value=
<?php
echo
$v
;
?>
<?php
echo
((
$value
[
'value'
]
==
$v
)
?
"checked"
:
""
);
?>
<?php
echo
$value
[
'events'
];
?>
>
<?php
echo
$n
;
?>
</label
>
<?php
}
break
;
default
:
break
;
<tr><td>
Book Year
</td>
<td>
<?php
print
"<input type=
\"
text
\"
name=
\"
timesheet_book_year
\"
id=
\"
book_year
\"
value=
\"
"
.
$config
[
'timesheet_book_year'
]
.
"
\"
pattern=
\"
^\s*\d
{
4
}
\"
size=4 required />"
;
?>
</td>
</tr>
<tr><td>
Approval by
</td>
<td>
<select
name=
"timesheet_approval_by"
size=
"1"
class=
"text"
>
<?php
foreach
(
$users
as
$u
=>
$n
)
{
$selected
=
''
;
if
(
$u
==
$config
[
'timesheet_approval_by'
])
$selected
=
' selected'
;
print
"<option "
.
$u
.
$selected
.
" value=
\"
"
.
$u
.
"
\"
>"
.
$users
[
$u
]
.
"</option>"
;
print
"
\n
"
;
}
?>
</td>
<?php
}
?>
</tr>
<?php
}
?>
<tr>
<td
colspan=
"2"
align=
"right"
>
<input
type=
"Submit"
name=
"Cancel"
value=
"
<?php
echo
$AppUI
->
_
(
'cancel'
)
?>
"
>
<input
type=
"Submit"
name=
"Save"
value=
"
<?php
echo
$AppUI
->
_
(
'save'
)
?>
"
>
</td>
</tr>
?>
</td>
</tr>
<tr><td>
Sort order
</td>
<td>
<select
name=
"timesheet_sort_order"
size=
"1"
class=
"text"
>
<?php
foreach
(
$order
as
$o
=>
$n
)
{
$selected
=
''
;
if
(
strcasecmp
(
$order
[
$o
],
$config
[
'timesheet_sort_order'
])
==
0
)
$selected
=
' selected'
;
print
"<option "
.
$o
.
$selected
.
" value=
\"
"
.
$order
[
$o
]
.
"
\"
>"
.
$order
[
$o
]
.
"</option>"
;
print
"
\n
"
;
}
?>
</td>
</tr>
<tr><td
align=
"left"
>
<input
type=
"Submit"
name=
"back"
value=
"
<?php
echo
$AppUI
->
_
(
'back'
)
?>
"
>
</td>
<td
align=
"right"
>
<input
type=
"Submit"
name=
"submit"
value=
"
<?php
echo
$AppUI
->
_
(
'submit'
)
?>
"
>
</td>
</tr>
</table>
</form>
setup.php
View file @
8f431fdf
...
...
@@ -2,14 +2,14 @@
/*
* Name: Timesheet
* Directory: timesheet
* Version:
1.0.2
* Version:
3.0.0
* Type: user
* UI Name: Timesheet
* UI Icon:
*/
/*
* Copyright (C) 2007-20
08, M2X
* Copyright (C) 2007-20
14, M2X BV
*
* Authors: Jean-Paul Saman
*
...
...
@@ -31,31 +31,40 @@
// MODULE CONFIGURATION DEFINITION
$config
=
array
();
$config
[
'mod_name'
]
=
'Timesheet'
;
// name the module
$config
[
'mod_version'
]
=
'
2.0.3
'
;
// add a version number
$config
[
'mod_version'
]
=
'
3.0.0
'
;
// add a version number
$config
[
'mod_directory'
]
=
'timesheet'
;
// tell dotProject where to find this module
$config
[
'mod_setup_class'
]
=
'CSetupTimesheet'
;
// the name of the PHP setup class (used below)
$config
[
'mod_type'
]
=
'user'
;
// 'core' for modules distributed with dP by standard, 'user' for additional modules from dotmods
$config
[
'mod_ui_name'
]
=
'Timesheet'
;
// the name that is shown in the main menu of the User Interface
$config
[
'mod_ui_name'
]
=
$config
[
'mod_name'
];
// the name that is shown in the main menu of the User Interface
$config
[
'mod_ui_icon'
]
=
'communicate.gif'
;
// name of a related icon
$config
[
'mod_description'
]
=
'Timesheet module for hour registration'
;
// some description of the module
$config
[
'mod_config'
]
=
true
;
// show 'configure' link in viewmods
$config
[
'mod_config'
]
=
true
;
// show 'configure' link in viewmods
$config
[
'mod_main_class'
]
=
'CTimesheet'
;
// this is the table the system should check for permissions
// show module configuration with the dPframework (if requested via http)
$config
[
'permission_item_table'
]
=
'timesheet'
;
$config
[
'permissions_item_field'
]
=
'timesheet_id'
;
$config
[
'permissions_item_label'
]
=
'timesheet_period'
;
// show module configuration in 'System Administration|View Modules'
if
(
@
$a
==
'setup'
)
{
echo
dPshowModuleConfig
(
$config
);
echo
w2PshowModuleConfig
(
$config
);
}
class
CSetupTimesheet
{
$config
[
'requirements'
]
=
array
(
array
(
'require'
=>
'web2project'
,
'comparator'
=>
'>='
,
'version'
=>
'3'
)
);
function
configure
()
{
class
CSetupTimesheet
extends
w2p_Core_Setup
{
public
function
configure
()
{
// load module specific configuration page
global
$AppUI
;
$AppUI
->
redirect
(
'm=timesheet&a=configure'
);
// load module specific configuration page
$AppUI
->
redirect
(
'm=timesheet&a=configure'
);
return
true
;
}
function
remove
()
{
$q
=
new
DBQuery
();
public
function
remove
()
{
$q
=
new
w2p_Database_Query
();
$q
->
dropTable
(
'timesheet'
);
$q
->
exec
();
...
...
@@ -63,35 +72,83 @@ class CSetupTimesheet {
$q
->
dropTable
(
'timesheet_project'
);
$q
->
exec
();
return
null
;
}
$q
->
clear
();
$q
->
dropTable
(
'timesheet_config'
);
$q
->
exec
();
function
upgrade
(
$old_version
)
{
// use this to provide upgrade functionality between different versions; not relevant here
return
parent
::
remove
();
}
switch
(
$old_version
)
{
case
"all"
:
// upgrade from scratch (called from install)
case
"0.9"
:
//do some alter table commands
public
function
upgrade
(
$old_version
)
{
// use this to provide upgrade functionality between different versions
$result
=
false
;
switch
(
$old_version
)
{
case
'all'
:
// upgrade from scratch (called from install)
case
'0.9'
:
case
'1.0'
:
case
'1.0.1'
:
case
'1.0.2'
:
case
'2.0.0'
:
case
'2.0.1'
:
case
'2.0.2'
:
case
'2.0.3'
:
$result
=
$this
->
_createConfigurationTable
();
if
(
!
$result
)
{
db_error
();
return
false
;
}
$result
=
$this
->
_insertConfigurationData
();
if
(
!
$result
)
{
db_error
();
return
false
;
}
case
'3.0.0'
:
default
:
// do nothing
}
case
"1.0"
:
case
"1.0.1"
:
case
"1.0.2"
:
case
"2.0.0"
:
case
"2.0.1"
;
case
"2.0.2"
:
return
true
;
return
$result
;
}
default
:
public
function
install
()
{
$result
=
$this
->
_checkRequirements
();
if
(
!
$result
)
{
return
false
;
}
return
false
;
// Timesheet table
$result
=
$this
->
createTimesheetTable
();
if
(
!
$result
)
{
db_error
();
return
false
;
}
// Timesheet project table
$result
=
$this
->
_createProjectTable
();
if
(
!
$result
)
{
db_error
();
return
false
;
}
// Timesheet configuration table
$result
=
$this
->
_createConfigurationTable
();
if
(
!
$result
)
{
db_error
();
return
false
;
}
$result
=
$this
->
_insertConfigurationData
();
if
(
!
$result
)
{
db_error
();
return
false
;
}
return
parent
::
install
();
}
function
install
()
{
// prepare the creation of a dbTable
private
function
_createTimesheetTable
()
{
$q
=
new
w2p_Database_Query
();
$sql
=
"( "
.
" `timesheet_id` int(11) unsigned NOT NULL auto_increment,"
.
" `timesheet_period` int(11) NOT NULL default '0', "
.
...
...
@@ -101,27 +158,53 @@ class CSetupTimesheet {
" `timesheet_worked` int(11) NOT NULL default '0', "
.
" PRIMARY KEY (`timesheet_id`), "
.
" UNIQUE KEY `timesheet_id` (`timesheet_id`) "
.
") TYPE=MyISAM"
;
$q
=
new
DBQuery
;
") ENGINE = MYISAM DEFAULT CHARSET=utf8"
;
$q
->
createTable
(
'timesheet'
);
$q
->
createDefinition
(
$sql
);
if
(
!
$q
->
exec
())
{
db_error
();
}
$result
=
$q
->
exec
();
return
$result
;
}
private
function
_createProjectTable
()
{
$q
=
new
w2p_Database_Query
();
$sql
=
"( "
.
" `timesheet_queue_id` int(11) NOT NULL auto_increment, "
.
" `timesheet_id` int(11) unsigned NOT NULL, "
.
" `timesheet_project` int(11) NOT NULL default '0', "
.
" `timesheet_project_amount` bigint(20) NOT NULL default '0', "
.
" PRIMARY KEY (`timesheet_queue_id`) "
.
")
TYPE=MyISAM
"
;
")
ENGINE = MYISAM DEFAULT CHARSET=utf8
"
;
$q
->
clear
();
$q
->
createTable
(
'timesheet_project'
);
$q
->
createDefinition
(
$sql
);
if
(
!
$q
->
exec
())
{
db_error
();
}
return
null
;
$result
=
$q
->
exec
();
return
$result
;
}
private
function
_createConfigurationTable
()
{
$q
=
new
w2p_Database_Query
();
$sql
=
"( "
.
" `timesheet_config` varchar(25) NOT NULL, "
.
" `timesheet_value` varchar(25), "
.
" PRIMARY KEY (`timesheet_config`) "
.
") ENGINE = MYISAM DEFAULT CHARSET = utf8"
;
$q
->
createTable
(
'timesheet_config'
);
$q
->
createDefinition
(
$sql
);
$result
=
$q
->
exec
();
return
$result
;
}
private
function
_insertConfigurationData
()
{
$q
=
new
w2p_Database_Query
();
$q
->
addTable
(
'timesheet_config'
);
$q
->
addInsert
(
'timesheet_config'
,
'timesheet_approval_by'
);
$q
->
addInsert
(
'timesheet_value'
,
'0'
);
$q
->
addInsert
(
'timesheet_config'
,
'timesheet_book_year'
);
$q
->
addInsert
(
'timesheet_value'
,
'2014'
);
$q
->
addInsert
(
'timesheet_config'
,
'timesheet_sort_order'
);
$q
->
addInsert
(
'timesheet_value'
,
'Ascending'
);
$result
=
$q
->
exec
();
return
$result
;
}
}
...
...
Write
Preview
Markdown
is supported
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