Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 254 lines (200 sloc) 6.195 kb
e85094a base module
aboynejames authored
1 <?php
2
3 /**
4 * Implements hook_permission().
5 *
6 * Since the access to our new custom pages will be granted based on
7 * special permissions, we need to define what those permissions are here.
8 * This ensures that they are available to enable on the user role
9 * administration pages.
10 */
11 function train_build_permission() {
12 return array(
13 'sct build' => array(
14 'title' => t('train test form'),
15 'description' => t('Only coach can add data for now'),
16 ),
17 );
18 }
19
20
21
22
23 function train_build_menu() {
24 $items = array();
25 $items['sct/train_build/form'] = array(
26 'title' => t('Build set element'),
27 'description' => t('Swim Entry'),
28 // 'access callback' => TRUE,
29 'page callback' => 'train_build_form',
30 'access arguments' => array('sct build'),
31 'type' => MENU_NORMAL_ITEM,
32 );
33 return $items;
34 }
35
36 // This function gets called in the browser address bar for:
37 //"http://yourhost/my_module/form" or
38 //"http://yourhost/?q=my_module/form". It will generate// a page with //this form on it.
39
40 function train_build_form() {
41
42 // This form calls the form builder function via the
43 // drupal_get_form() function which takes the name of this form builder
44 // function as an argument. It returns the results to display the form.
45 return drupal_get_form('train_build_my_form');
46
47 }
48
49 /*
50 function train_test_my_form() {
51 return array('#markup' => '<p>' . t('Simple page: The quick brown fox jumps over the lazy dog.') . '</p>');
52 }
53 */
54
55
56
57 // This function is called the "form builder". It builds the form.
58 // Notice, it takes one argument, the $form_state
59 function train_build_my_form($form, &$form_state) {
60
61
62 // Otherwise we build page 1.
63 $form_state['page_num'] = 1;
64
65
66
67 $today = date("d.m.y");
68
69 $form['session_date'] = array(
70 '#type' => 'textfield',
71 '#default_value' => $today,
72 //'#type' => 'hidden',
73 //'#value' => '233',
74 '#title' => t('swim date in'),
75 '#required' => TRUE, // Added
76 );
77
78
79 $form['set_type'] = array(
80 '#type' => 'radios',
81 '#options' => array(
82 '1' => t('warmup'),
83 '2' => t('main'),
84 '3' => t('warmdown'),
85 ),
86 '#title' => t('Type of set'),
87 '#default_value' => 2,
88
89 );
90
91
92 $form['pool_size'] = array(
93 '#type' => 'radios',
94 '#options' => array(
95 '25' => t('25 metre'),
96 '50' => t('50 metre'),
97 ),
98 '#title' => t('Swimming pool size'),
99 '#default_value' => 25,
100
101 );
102
103
104 $form['session_type'] = array(
105 '#type' => 'radios',
106 '#options' => array(
107 'training' => t('Training'),
108 'competition' => t('Competition'),
109 ),
110 '#title' => t('Please select session status'),
111 '#default_value' => 'training',
112 );
113
114
115 $form['stroke_type'] = array(
116 '#type' => 'radios',
117 '#options' => array(
118 'freestyle' => t('Freestyle'),
119 'backcrawl' => t('Backcrawl'),
120 'butterfly' => t('butterfly'),
121 'breaststroke' => t('Breaststroke'),
122 'im' => t('Individual Medaly'),
123 ),
124 '#title' => t('Please select a swimming stroke'),
125 '#default_value' => 'freestyle',
126 );
127
128 $form['swim_type'] = array(
129 '#type' => 'radios',
130 '#options' => array(
131 'swim' => t('Swim'),
132 'kick' => t('Kick'),
133 'race' => t('Race'),
134 'drill' => t('Drill'),
135 'pull' => t('Pull'),
136 'hvo' => t('HVO'),
137 ),
138 '#title' => t('Please select type of swim'),
139 '#default_value' => 'swim',
140 );
141
142 $form['swim_distance'] = array(
143 '#type' => 'radios',
144 '#options' => array(
145 '25' => t('25m'),
146 '50' => t('50m'),
147 '75' => t('75m'),
148 '100' => t('100m'),
149 '150' => t('150m'),
150 '200' => t('200m'),
151 '300' => t('300m'),
152 '400' => t('400m'),
153 '800' => t('800m'),
154 '1500' => t('1500m'),
155 '5' => t('5m'),
156 '10' => t('10m'),
157 '20' => t('20m'),
158 'sto5' => t('Start to 5m'),
159 'sto10' => t('Start to 10m'),
160 'sto15' => t('Start to 15m'),
161 'turntime' => t('Turn time'),
162 '5to5' => t('5m to 5m'),
163
164
165 ),
166 '#title' => t('Please select distance being recorded'),
167 '#default_value' => 100,
168 );
169
170
171 $form['split_distance'] = array(
172 '#type' => 'radios',
173 '#options' => array(
3bdbf40 update to split input logic
aboynejames authored
174 '1' => t('No split required'),
e85094a base module
aboynejames authored
175 '25' => t('25m'),
176 '50' => t('50m'),
177 '75' => t('75m'),
178 '100' => t('100m'),
179 '200' => t('200m'),
180 ),
181 '#title' => t('Please select split time intervals (if required)'),
3bdbf40 update to split input logic
aboynejames authored
182 '#default_value' => 1,
e85094a base module
aboynejames authored
183 );
184
185
186 $reps = array(
187 '1' => t('One'),
188 '2' => t('Two'),
189 '3' => t('Three'),
190 '4' => t('Four'),
191 '5' => t('Five'),
192 '6' => t('Six'),
193 '7' => t('Seven'),
194 '8' => t('Eight'),
195 '9' => t('Nine'),
196 '10' => t('Ten'),
197 '12' => t('Twelve'),
198 '14' => t('Fourteen'),
199 '16' => t('Sixteen'),
200 '18' => t('Eighteen'),
201 '20' => t('Twenty')
202 );
203
204 $form['repetitions'] = array(
205 '#type' => 'select',
206 '#options' => $reps,
207 '#title' => t('How many repetitions?'),
208 );
209
210
211 $form['next'] = array(
212 '#type' => 'submit',
213 '#value' => 'Add set',
214 '#submit' => array('train_build_my_form_submit'),
215 );
216
217 //drupal_set_message(t('First set form <pre>@result</pre>',
218 // array( '@result' => print_r($form_state, TRUE))));
219
220 return $form;
221
222 }
223
224
225
226 function train_build_my_form_submit($form, &$form_state)
227 {
228
229
230 // the set can be saved
231
232 // need to convert date to unix time or sql compatible
233 $unixtimeswim = strtotime($form_state['values']['session_date']);
234
235 $sdatain = db_insert('set_swim')
236 ->fields(array( 'setdate', 'set_type', 'poolsize', 'session_type', 'stroke_type', 'swim_type', 'swim_distance', 'split_distance', 'reps'))
237 ->values(array(
238 'setdate' => $unixtimeswim,
239 'set_type' => $form_state['values']['set_type'],
240 'poolsize' => $form_state['values']['pool_size'],
241 'session_type' => $form_state['values']['session_type'],
242 'stroke_type' => $form_state['values']['stroke_type'],
243 'swim_type' => $form_state['values']['swim_type'],
244 'swim_distance' => $form_state['values']['swim_distance'],
245 'split_distance' => $form_state['values']['split_distance'],
246 'reps' => $form_state['values']['repetitions'],
247 ))
248 ->execute();
249
250 $form_state['setid'] = $sdatain;
251
252 }
253
Something went wrong with that request. Please try again.