More fixes due the recent changes in session fields

skala
Julio Montoya 12 years ago
parent 4e0405ba9b
commit 55e9d1ee90
  1. 23
      main/admin/extra_field_options.php
  2. 3
      main/inc/lib/database.lib.php
  3. 28
      main/inc/lib/extra_field_option.lib.php
  4. 1
      main/inc/lib/session_field.lib.php

@ -39,13 +39,18 @@ $check = Security::check_token('request');
$token = Security::get_token(); $token = Security::get_token();
if ($action == 'add') { if ($action == 'add') {
$interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields')); $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields'));
$interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
$interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Add')); $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
} elseif ($action == 'edit') { } elseif ($action == 'edit') {
$interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields')); $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields'));
$interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
$interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit')); $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
} else { } else {
$interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields')); $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields'));
$interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']); $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
$interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions')); $interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions'));
} }
@ -90,7 +95,7 @@ Display::display_header($tool_name);
echo Display::page_header($extra_field_info['field_display_text']); echo Display::page_header($extra_field_info['field_display_text']);
$obj = new ExtraFieldOption($type); $obj = new ExtraFieldOption($type);
//$obj->field_id = $field_id; $obj->field_id = $field_id;
// Action handling: Add // Action handling: Add
switch ($action) { switch ($action) {
@ -105,16 +110,16 @@ switch ($action) {
if ($form->validate()) { if ($form->validate()) {
if ($check) { if ($check) {
$values = $form->exportValues(); $values = $form->exportValues();
$res = $obj->save($values); $res = $obj->save_one_item($values);
if ($res) { if ($res) {
Display::display_confirmation_message(get_lang('ItemAdded')); Display::display_confirmation_message(get_lang('ItemAdded'));
} }
} }
$obj->display(); $obj->display();
} else { } else {
echo '<div class="actions">'; /*echo '<div class="actions">';
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>'; echo '</div>'; */
$form->addElement('hidden', 'sec_token'); $form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token)); $form->setConstants(array('sec_token' => $token));
$form->display(); $form->display();
@ -134,9 +139,9 @@ switch ($action) {
} }
$obj->display(); $obj->display();
} else { } else {
echo '<div class="actions">'; /*echo '<div class="actions">';
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>'; echo '</div>';*/
$form->addElement('hidden', 'sec_token'); $form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token)); $form->setConstants(array('sec_token' => $token));
$form->display(); $form->display();

@ -1177,7 +1177,6 @@ class Database {
* @example array('where'=> array('type = ? AND category = ?' => array('setting', 'Plugins')) * @example array('where'=> array('type = ? AND category = ?' => array('setting', 'Plugins'))
* @example array('where'=> array('name = "Julio" AND lastname = "montoya")) * @example array('where'=> array('name = "Julio" AND lastname = "montoya"))
*/ */
public static function select($columns, $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') { public static function select($columns, $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') {
$conditions = self::parse_conditions($conditions); $conditions = self::parse_conditions($conditions);
@ -1192,7 +1191,6 @@ class Database {
$clean_columns = (string)$columns; $clean_columns = (string)$columns;
} }
} }
$sql = "SELECT $clean_columns FROM $table_name $conditions"; $sql = "SELECT $clean_columns FROM $table_name $conditions";
//var_dump($sql); //var_dump($sql);
$result = self::query($sql); $result = self::query($sql);
@ -1230,7 +1228,6 @@ class Database {
$type_condition = strtolower($type_condition); $type_condition = strtolower($type_condition);
switch ($type_condition) { switch ($type_condition) {
case 'where': case 'where':
foreach ($condition_data as $condition => $value_array) { foreach ($condition_data as $condition => $value_array) {
if (is_array($value_array)) { if (is_array($value_array)) {
$clean_values = array(); $clean_values = array();

@ -22,7 +22,7 @@ class ExtraFieldOption extends Model {
} }
public function get_count_by_field_id($field_id) { public function get_count_by_field_id($field_id) {
$row = Database::select('count(*) as count', $this->table, array('where' => array('field_id = ?', $field_id)), 'first'); $row = Database::select('count(*) as count', $this->table, array('where' => array('field_id = ?' => $field_id)), 'first');
return $row['count']; return $row['count'];
} }
@ -131,6 +131,21 @@ class ExtraFieldOption extends Model {
return true; return true;
} }
public function save_one_item($params, $show_query = false) {
$field_id = intval($params['field_id']);
if (empty($field_id)) {
return false;
}
$params['tms'] = api_get_utc_datetime();
if (empty($params['option_order'])) {
$order = self::get_max_order($field_id);
$params['option_order'] = $order;
}
parent::save($params, $show_query);
}
public function get_field_option_by_field_and_option($field_id, $option_value) { public function get_field_option_by_field_and_option($field_id, $option_value) {
$field_id = intval($field_id); $field_id = intval($field_id);
$option_value = Database::escape_string($option_value); $option_value = Database::escape_string($option_value);
@ -253,7 +268,8 @@ class ExtraFieldOption extends Model {
// action links // action links
echo '<div class="actions">'; echo '<div class="actions">';
//echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'', ICON_SIZE_MEDIUM).'</a>'; //echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('add_user_fields.png',get_lang('Add'),'', ICON_SIZE_MEDIUM).'</a>'; $field_id = isset($_REQUEST['field_id']) ? intval($_REQUEST['field_id']) : null;
echo '<a href="'.api_get_self().'?action=add&type='.$this->type.'&field_id='.$field_id.'">'.Display::return_icon('add_user_fields.png',get_lang('Add'),'', ICON_SIZE_MEDIUM).'</a>';
echo '</div>'; echo '</div>';
echo Display::grid_html('extra_field_options'); echo Display::grid_html('extra_field_options');
} }
@ -269,19 +285,21 @@ class ExtraFieldOption extends Model {
$form->addElement('header', $header); $form->addElement('header', $header);
$id = isset($_GET['id']) ? intval($_GET['id']) : ''; $id = isset($_GET['id']) ? intval($_GET['id']) : '';
$form->addElement('hidden', 'id', $id);
//$form->addElement('hidden', 'type', $this->type);
//$form->addElement('hidden', 'field_id', $this->field_id);
$form->addElement('hidden', 'id', $id);
$form->addElement('hidden', 'type', $this->type);
$form->addElement('hidden', 'field_id', $this->field_id);
$form->addElement('text', 'option_display_text', get_lang('Name'), array('class' => 'span5')); $form->addElement('text', 'option_display_text', get_lang('Name'), array('class' => 'span5'));
$form->addElement('text', 'option_value', get_lang('Value'), array('class' => 'span5')); $form->addElement('text', 'option_value', get_lang('Value'), array('class' => 'span5'));
$form->addElement('text', 'option_order', get_lang('Order'), array('class' => 'span2'));
$defaults = array(); $defaults = array();
if ($action == 'edit') { if ($action == 'edit') {
// Setting the defaults // Setting the defaults
$defaults = $this->get($id); $defaults = $this->get($id);
$form->freeze('option_value');
$form->addElement('button', 'submit', get_lang('Modify'), 'class="save"'); $form->addElement('button', 'submit', get_lang('Modify'), 'class="save"');
} else { } else {
$form->addElement('button', 'submit', get_lang('Add'), 'class="save"'); $form->addElement('button', 'submit', get_lang('Add'), 'class="save"');

@ -52,6 +52,7 @@ class SessionField extends ExtraField {
if (in_array($defaults['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) { if (in_array($defaults['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
$url = Display::url(get_lang('EditExtraFieldOptions'), 'extra_field_options.php?type=session&field_id=' . $id); $url = Display::url(get_lang('EditExtraFieldOptions'), 'extra_field_options.php?type=session&field_id=' . $id);
$form->addElement('label', null, $url); $form->addElement('label', null, $url);
$form->freeze('field_options');
} }
} }
$form->addElement('text', 'field_default_value', get_lang('FieldDefaultValue'), array('id' => 'field_default_value', 'class' => 'span5')); $form->addElement('text', 'field_default_value', get_lang('FieldDefaultValue'), array('id' => 'field_default_value', 'class' => 'span5'));

Loading…
Cancel
Save