-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooms_ui.module
More file actions
256 lines (238 loc) · 10.3 KB
/
rooms_ui.module
File metadata and controls
256 lines (238 loc) · 10.3 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
/**
* @file
* Interface support to the Rooms family of modules.
*/
/**
* Implements hook_menu().
*/
function rooms_ui_menu() {
$items = array();
// Top level "Rooms" container.
$items['admin/rooms'] = array(
'title' => 'Rooms',
'description' => t('Administer Rooms.'),
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
'weight' => -7,
);
$items['admin/rooms/config'] = array(
'title' => t('Configuration'),
'description' => t('Configure settings and business rules for Rooms management.'),
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('configure room settings'),
'type' => MENU_NORMAL_ITEM,
'weight' => 10,
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
);
$items['admin/rooms/config/bookings'] = array(
'title' => t('Booking Settings'),
'description' => t('Configure settings and business rules for Bookings.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('rooms_booking_settings'),
'access arguments' => array('configure room settings'),
'type' => MENU_NORMAL_ITEM,
);
// Yani: add price/ menu setting menu - form
$items['admin/rooms/config/camping'] = array(
'title' => t('Camping search bar menu and price settings'),
'description' => t('Configure price and menu links for the camping place.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('camping_price_settings'),
'access arguments' => array('configure room settings'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function rooms_booking_settings() {
$form = array();
$form['rooms_booking_settings']['rooms_booking_start_date'] = array(
'#type' => 'select',
'#title' => t('How soon a booking can start'),
'#options' => array(
'0' => t('Same day bookings'),
'1' => t('1 day in advance'),
'2' => t('2 days in advance'),
'3' => t('3 days in advance'),
'4' => t('4 days in advance'),
'5' => t('5 days in advance'),
'6' => t('6 days in advance'),
'7' => t('7 days in advance'),
),
'#default_value' => variable_get('rooms_booking_start_date', 1),
);
return system_settings_form($form);
}
// Yani : add setting page for price
function camping_price_settings() {
$form = array();
$form['vertical_settings_tab'] = array(
'#type' => 'vertical_tabs',
'#weight' => 0,
);
// Form element. It's a fieldset , "Menu link to type"
$form['camping_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Camping menu'),
'#collapsible' => TRUE,
'#group' => 'vertical_settings_tab',
);
$menu_option = array();
$existing_menu = db_query("SELECT * FROM {menu_links} where menu_name = 'menu-camping-menu'");
if ($existing_menu) {
foreach ($existing_menu as $menu_item) {
//$menu_name = $menu_item->menu_name;
$menu_title = strtolower($menu_item->link_title);
$menu_option[$menu_title] = $menu_title;
$form['camping_settings']["camping_setting_menu_links_$menu_title"] = array(
'#type' => 'textfield',
'#title' => t("menu link -'$menu_title'"),
'#description' => t("Go to admin/rooms/units/unit-types to find the machine name of the type. Add ',' after every value for multi type"),
'#default_value' => variable_get("camping_setting_menu_links_$menu_title", ''),
);
}
}
$form['camping_settings_children_age'] = array(
'#type' => 'fieldset',
'#title' => t('Children age'),
'#collapsible' => TRUE,
'#group' => 'vertical_settings_tab',
);
$form['camping_settings_children_age']["children_age"] = array(
'#type' => 'textfield',
'#title' => t("Children age"),
'#description' => t("e.g. 16"),
'#default_value' => variable_get('children_age',16),
);
// Form element. It's a fieldset , "tent price"
$form['camping_settings_price'] = array(
'#type' => 'fieldset',
'#title' => t('Camping tent price'),
'#collapsible' => TRUE,
'#group' => 'vertical_settings_tab',
);
$form['camping_settings_price']["camping_setting_price_adults"] = array(
'#type' => 'textfield',
'#title' => t("Price for adults per night"),
'#description' => t("e.g. 69"),
'#default_value' => variable_get('camping_setting_price_adults'),
);
$form['camping_settings_price']["camping_setting_price_children"] = array(
'#type' => 'textfield',
'#title' => t("Price for children per night"),
'#description' => t("e.g 39"),
'#default_value' => variable_get('camping_setting_price_children'),
);
$unit_types = rooms_unit_types_ids();
foreach ($unit_types as $unit_type => $unit_label) {
$form['camping_settings_' . $unit_type] = array(
'#type' => 'fieldset',
'#title' => t('Camping ' . $unit_label . ' prices'),
'#collapsible' => TRUE,
'#group' => 'vertical_settings_tab',
);
$form['camping_settings_' . $unit_type]['camping_setting_include_price_per_person_' . $unit_type] = array(
'#type' => 'checkbox',
'#title' => t($unit_label . ' Calculate price including number of children/adults.'),
'#default_value' => variable_get('camping_setting_include_price_per_person_' . $unit_type, FALSE),
);
$form['camping_settings_' . $unit_type]['camping_setting_enable_seasons_' . $unit_type] = array(
'#type' => 'checkbox',
'#title' => t('Enable seasons calculations for ' . $unit_type),
'#default_value' => variable_get('camping_setting_enable_seasons_' . $unit_type, FALSE),
);
$form['camping_settings_' . $unit_type]['low'] = array(
'#type' => 'fieldset',
'#title' => t('Camping ' . $unit_label . ' low season'),
'#collapsible' => FALSE,
);
$form['camping_settings_' . $unit_type]['low']['camping_setting_price_' . $unit_type . '_day'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' Low Season day price'),
'#description' => t("e.g. 475"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_day'),
);
$form['camping_settings_' . $unit_type]['low']['camping_setting_price_' . $unit_type . '_4'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' price for 4 days'),
'#description' => t("e.g. 1695"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_4'),
);
$form['camping_settings_' . $unit_type]['low']['camping_setting_price_' . $unit_type . '_7'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' price for one week'),
'#description' => t("e.g 2775"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_7'),
);
$form['camping_settings_' . $unit_type]['low']['camping_setting_price_' . $unit_type . '_weekend'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' price for one weekend'),
'#description' => t("e.g 2500"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_weekend'),
);
$form['camping_settings_' . $unit_type]['high'] = array(
'#type' => 'fieldset',
'#title' => t('Camping ' . $unit_label . ' high season'),
'#collapsible' => FALSE,
);
$form['camping_settings_' . $unit_type]['high']['camping_setting_price_' . $unit_type . '_day_high'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' High Season day price'),
'#description' => t("e.g. 549"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_day_high'),
);
$form['camping_settings_' . $unit_type]['high']['camping_setting_price_' . $unit_type . '_4_high'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' price for 4 days'),
'#description' => t("e.g. 1995"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_4_high'),
);
$form['camping_settings_' . $unit_type]['high']['camping_setting_price_' . $unit_type . '_7_high'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' price for one week'),
'#description' => t("e.g 3275"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_7_high'),
);
$form['camping_settings_' . $unit_type]['high']['camping_setting_price_' . $unit_type . '_weekend_high'] = array(
'#type' => 'textfield',
'#title' => t($unit_label . ' price for one weekend'),
'#description' => t("e.g 2500"),
'#default_value' => variable_get('camping_setting_price_' . $unit_type . '_weekend_high'),
);
}
// Yani: add another product type for the options like electricity, dogs, cats and so on.
$query= db_select('commerce_product', 'c')->fields('c', array('product_id', 'sku'));
$query->condition('type', 'product' , '=');
$option_products = $query->execute()->fetchAll();
if (isset($option_products)) {
foreach ($option_products as $option_product) {
$product_id = $option_product->product_id;
$product_sku = $option_product->sku;
$product = commerce_product_load($product_id);
$product_pris_amount = $product->commerce_price['und'][0]['amount'];
$product_pris_currency = $product->commerce_price['und'][0]['currency_code'];
$product_pris = commerce_currency_format($product_pris_amount,$product_pris_currency,$product,TRUE);
$product_info = $product->title. " - " .$product_pris ;
$pris_no = $product_pris_amount/100;
// Form element. It's a fieldset , "Menu link to type"
$form['camping_options_setting'.$product_id] = array(
'#type' => 'fieldset',
'#title' => t('Camping tilvalg'). " ".$product_sku,
'#collapsible' => TRUE,
'#group' => 'vertical_settings_tab',
);
foreach ($unit_types as $unit_type => $unit_label) {
$form['camping_options_setting'.$product_id]["camping_options_setting_".$unit_type."_".$product_id] = array(
'#type' => 'textfield',
'#title' => t("Tilvalg -'$product_sku' pris i typen") . " - ".$unit_label,
'#description' => t("Indtast heltal,f. eks. '33' i telt, '0' i hytter (El)"),
'#default_value' => variable_get("camping_options_setting_".$unit_type."_".$product_id, $pris_no),
);
}
}
}
return system_settings_form($form);
}