/
work_registration_fields.php
executable file
·200 lines (154 loc) · 6.39 KB
/
work_registration_fields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $wpdb;
$project_value = '';
$subscription_value = '';
$extra_select = '';
$extra_join = '';
$project_query = "
SELECT
project.name AS project_name,
project.number_seconds AS project_time
$extra_select
FROM
$wpdb->orbis_projects AS project
$extra_join
WHERE
project.finished = 0
AND
project.id = %s
";
if ( property_exists( $wpdb, 'orbis_companies' ) ) {
$extra_select .= '
, principal.name AS principal_name
';
$extra_join .= "
LEFT JOIN
$wpdb->orbis_companies AS principal
ON project.principal_id = principal.id
";
}
$project_query = $wpdb->prepare( $project_query, $entry->project_id );
$project = $wpdb->get_row( $project_query );
if ( $project ) {
$project_value = sprintf(
'%s. %s - %s ( %s )',
$entry->project_id,
$project->principal_name,
$project->project_name,
orbis_time( $project->project_time )
);
}
if ( property_exists( $wpdb, 'orbis_subscriptions' ) ) {
$subscription_query = "
SELECT
subscription.id AS id,
CONCAT( subscription.id, '. ', IFNULL( CONCAT( product.name, ' - ' ), '' ), subscription.name ) AS text
FROM
$wpdb->orbis_subscriptions AS subscription
LEFT JOIN
$wpdb->orbis_subscription_products AS product
ON subscription.type_id = product.id
WHERE
subscription.cancel_date IS NULL
AND
subscription.id = %s
";
$subscription_query = $wpdb->prepare( $subscription_query, $entry->subscription_id );
$subscription = $wpdb->get_row( $subscription_query );
$subscription_value = ( $subscription ) ? $subscription->text : '';
}
?>
<?php if ( ! empty( $orbis_errors ) ) : ?>
<div class="alert alert-danger">
<p>
<?php
echo implode( '<br />', array_filter( $orbis_errors ) );
?>
</p>
</div>
<?php endif; ?>
<?php $tabindex = 2; ?>
<input name="orbis_registration_id" value="<?php echo esc_attr( $entry->id ); ?>" type="hidden" />
<input name="orbis_registration_date" value="<?php echo $entry->get_date()->format( 'Y-m-d' ); ?>" type="hidden" />
<div class="row">
<?php if ( false ) : ?>
<div class="col-md-6">
<div <?php orbis_field_class( [ 'mb-3' ], 'orbis_registration_company_id' ); ?>>
<label class="form-label"><?php _e( 'Company', 'orbis-timesheets' ); ?></label>
<input class="form-control" placeholder="<?php esc_attr_e( 'Select company…', 'orbis-timesheets' ); ?>" type="text" name="orbis_registration_company_id" value="<?php echo esc_attr( $entry->company_id ); ?>" class="orbis-id-control orbis-company-id-control select-form-control" data-text="<?php echo esc_attr( $entry->company_name ); ?>" tabindex="<?php echo esc_attr( $tabindex++ ); ?>" />
</div>
</div>
<?php endif; ?>
<?php if ( true ) : ?>
<div class="col-md-6">
<div <?php orbis_field_class( [ 'mb-3' ], 'orbis_registration_project_id' ); ?>>
<label class="form-label"><?php _e( 'Project', 'orbis-timesheets' ); ?></label>
<select name="orbis_registration_project_id" class="custom-select orbis-id-control orbis-project-id-control select-form-control" data-placeholder="<?php esc_attr_e( 'Select project…', 'orbis-timesheets' ); ?>" tabindex="<?php echo esc_attr( $tabindex++ ); ?>" autofocus>
<option selected="selected" value="<?php echo esc_attr( $entry->project_id ); ?>">
<?php echo esc_attr( $project_value ); ?>
</option>
</select>
</div>
</div>
<?php endif; ?>
<?php if ( property_exists( $wpdb, 'orbis_subscriptions' ) ) : ?>
<div class="col-md-6">
<div <?php orbis_field_class( [ 'mb-3' ], 'orbis_registration_subscription_id' ); ?>>
<label class="form-label"><?php _e( 'Subscription', 'orbis-timesheets' ); ?></label>
<select name="orbis_registration_subscription_id" class="custom-select orbis-id-control orbis-subscription-id-control select-form-control" data-placeholder="<?php esc_attr_e( 'Select subscription…', 'orbis-timesheets' ); ?>" tabindex="<?php echo esc_attr( $tabindex++ ); ?>">
<option selected="selected" value="<?php echo esc_attr( $entry->subscription_id ); ?>">
<?php echo esc_attr( $subscription_value ); ?>
</option>
</select>
</div>
</div>
<?php endif; ?>
<div class="col-md-6">
<div <?php orbis_field_class( [ 'mb-3' ], 'orbis_registration_activity_id' ); ?>>
<label class="form-label"><?php _e( 'Activity', 'orbis-timesheets' ); ?></label>
<select name="orbis_registration_activity_id" class="select2 select-form-control" tabindex="<?php echo esc_attr( $tabindex++ ); ?>" data-placeholder="<?php esc_attr_e( 'Select activity…', 'orbis-timesheets' ); ?>" data-allow-clear="true" />
<option value=""></option>
<?php
foreach ( $activities as $activity ) {
printf(
'<option value="%s" %s>%s</option>',
esc_attr( $activity->id ),
selected( $activity->id, $entry->activity_id, false ),
esc_html( $activity->name )
);
}
?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div <?php orbis_field_class( [ 'mb-3' ], 'orbis_registration_description' ); ?>>
<label class="form-label"><?php _e( 'Description', 'orbis-timesheets' ); ?></label>
<textarea placeholder="<?php esc_attr_e( 'Work registration description', 'orbis-timesheets' ); ?>" name="orbis_registration_description" class="input-lg" cols="60" rows="5" tabindex="<?php echo esc_attr( $tabindex++ ); ?>"><?php echo esc_textarea( $entry->description ); ?></textarea>
</div>
</div>
<div class="col-md-6">
<div <?php orbis_field_class( [ 'mb-3', 'clearfix' ], 'orbis_registration_time' ); ?>>
<label class="form-label"><?php _e( 'Time', 'orbis-timesheets' ); ?></label>
<div class="row">
<div class="col-md-4">
<div class="input-group">
<input class="form-control" size="2" type="text" name="orbis_registration_hours" value="<?php echo empty( $entry->time ) ? '' : esc_attr( orbis_time( $entry->time, 'H' ) ); ?>" tabindex="<?php echo esc_attr( $tabindex++ ); ?>" />
<span class="input-group-text"><?php _e( 'hours', 'orbis-timesheets' ); ?></span>
</div>
</div>
<div class="col-md-4">
<div class="input-group">
<input class="form-control" size="2" type="text" name="orbis_registration_minutes" value="<?php echo empty( $entry->time ) ? '' : esc_attr( orbis_time( $entry->time, 'M' ) ); ?>" tabindex="<?php echo esc_attr( $tabindex++ ); ?>" />
<span class="input-group-text"><?php _e( 'minutes', 'orbis-timesheets' ); ?></span>
</div>
</div>
</div>
</div>
</div>
</div>