-
-
Save codev0/b97460c2f28e5ec20154ba1ab5b09137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sl_kz_calc_update_form($form, &$form_state) | |
{ | |
// Получаем список калькуляторов | |
$calculators = db_select('sl_kz_calc', 'n')->fields('n', array('id', 'city_from', 'city_to', 'pricing', 'days')); | |
$calculators_result = $calculators->execute(); | |
// Получаем список городов | |
$cities = db_select('sl_kz_cities', 'n')->fields('n', array('id', 'city')); | |
$cities_result = $cities->execute(); | |
if ($calculators_result or $cities_result) { | |
return t("Cities is empty"); | |
} | |
$cities_list = array(); | |
$form['calculators'] = array( | |
'#tree' => TRUE, | |
'#theme' => 'tabular_form', // Функция, с помощью которой мы будем придавать форме табличный вид | |
'#header' => array( | |
'Id', | |
'Calculator values', | |
'Update city from', | |
'Update city to', | |
'Update pricing', | |
'Update days' | |
), // Заголовок таблицы | |
); | |
foreach ($cities_result as $item) { | |
$cities_list[$item->id] = $item->city; | |
} | |
theme('calculator_kz_delivery', array( | |
'param' => $cities_list, | |
)); | |
foreach ($calculators_result as $calc) { | |
$form['calculators'][$calc->id]['hidden'] = array( | |
'#type' => 'value', | |
'#value' => $calc->id, | |
); | |
$form['calculators'][$calc->id]['id'] = array( | |
'#markup' => $calc->id, | |
); | |
$form['calculators'][$calc->id]['city'] = array( | |
'#markup' => "От: " . $cities_list[$calc->city_from] . ". До: " . $cities_list[$calc->city_to] . "Цена: $calc->pricing. Дни: $calc->days", | |
); | |
$form['calculators'][$calc->id]['city_from'] = array( | |
'#type' => 'select', | |
'#default_value' => $calc->city_from, | |
'#options' => $cities_list, | |
); | |
$form['calculators'][$calc->id]['city_to'] = array( | |
'#type' => 'select', | |
'#default_value' => $calc->city_to, | |
'#options' => $cities_list, | |
); | |
$form['calculators'][$calc->id]['pricing'] = array( | |
'#type' => 'textfield', | |
'#default_value' => $calc->pricing, | |
'#required' => true, | |
'#size' => 10 | |
); | |
$form['calculators'][$calc->id]['days'] = array( | |
'#type' => 'textfield', | |
'#default_value' => $calc->days, | |
'#required' => true, | |
'#size' => 10 | |
); | |
} | |
$form['submit'] = array( | |
'#type' => 'submit', | |
'#value' => t('Update'), | |
); | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment