Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //
- // file: acp/acp_attributes.php
- // author: Adrien BONNEL
- // begin: 10/06/2010
- // version: 0.0.3 - 10/08/2010
- //
- // secure this file !
- define('IN_PHPBB', true);
- // show the menu !
- if ( !empty($setmodules) )
- {
- $file = basename(__FILE__);
- $module['01_General']['03_Attributes'] = $file;
- return;
- }
- // header
- $phpbb_root_path = './../';
- $phpEx = substr(strrchr(__FILE__, '.'), 1);
- $requester = 'admin/admin_attributes';
- require('./pagestart.' . $phpEx);
- // get parameters
- $cancel = request_var('cancel', TYPE_NO_HTML);
- $mode = request_var('mode', TYPE_NO_HTML);
- $no_page_header = $cancel;
- // define $mode with additional parameters
- $mode = _butt('submit_form') ? 'save' : ( _butt('cancel_form') ? '' : $mode);
- $mode = !empty($cancel) ? '' : $mode;
- // initialization
- $attr_id = request_var('id', TYPE_INT);
- // define a function for the order
- function attr_select_order($attr_order, $attr_id, $attr_tmp_order, $select)
- {
- global $db, $lang;
- $sql_where = !empty($select) ? ' WHERE attr_id <> ' . (int) $attr_id : '';
- $sql_order = !empty($attr_order) ? ' ORDER BY ' . $attr_order : '';
- $sql = 'SELECT * FROM ' . ATTRIBUTES_TABLE . $sql_where . $sql_order;
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- $this_order = $attr_tmp_order - 10;
- $attr_list_order = '<option value="0">' . $lang['Top'] . '</option>';
- while ( $row = $db->sql_fetchrow($result) )
- {
- $selected = ($row['attr_order'] == $this_order) ? ' selected="selected"' : '';
- $attr_list_order .= '<option value="' . $row['attr_order'] . '" style="font-weight:bold;"' . $selected . '>' . lng_key($row['attr_name']) . '</option>';
- }
- return $attr_list_order;
- }
- // just do it !
- switch ( $mode )
- {
- case 'add':
- case 'edit':
- if ( $mode == 'edit' )
- {
- if ( empty($attr_id) )
- {
- message_die(GENERAL_MESSAGE, 'Must_select_attr');
- }
- $sql = 'SELECT * FROM ' . ATTRIBUTES_TABLE . ' WHERE attr_id = ' . $attr_id;
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- $row = $db->sql_fetchrow($result);
- $tmp_order = $row['attr_order'];
- // generate the list
- $attr_list_order = attr_select_order('attr_order', $attr_id, $row['attr_order'], true);
- // hidden fields
- _hide_build(array('id' => $attr_id, 'attr_tmp_order' => $row['attr_order']));
- $template->assign_vars(array(
- 'L_TITLE' => $lang['Attr_edit'],
- 'L_EXPLAIN' => $lang['Attr_edit_exp'],
- 'ATTR_NAME' => $row['attr_name'],
- 'ATTR_IMG' => $row['attr_img'],
- 'ATTR_DATE' => $row['attr_date'],
- 'ATTR_COLOUR' => $row['attr_colour'],
- ));
- $get->assign_switch('img_type', $row['attr_type']);
- // checks the auths
- $attr_auths_ary = unserialize($row['attr_auths']);
- $attr_auths_ary_switch = array('attr_author', 'attr_mod', 'attr_admin');
- $attr_auths_ary_count = count($attr_auths_ary);
- for ( $i = 0; $i < $attr_auths_ary_count; $i++ )
- {
- $get->assign_switch($attr_auths_ary_switch[$i], !empty($attr_auths_ary[$i]));
- }
- }
- else
- {
- $sql = 'SELECT attr_id, attr_order FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order DESC LIMIT 1';
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- $row = $db->sql_fetchrow($result);
- // generate the list
- $attr_list_order = attr_select_order('attr_order', $row['attr_id'], $row['attr_order'], 0);
- // hidden fields
- _hide_build(array('attr_tmp_order' => $row['attr_order']));
- // increment this value
- $row['attr_order'] += 10;
- $template->assign_vars(array(
- 'L_TITLE' => $lang['Attr_add'],
- 'L_EXPLAIN' => $lang['Attr_add_exp'],
- ));
- }
- // send hidden fields to template
- _hide_send();
- // send to template
- $template->assign_vars(array(
- 'S_REQUESTER' => $get->url($requester, '', true),
- 'L_ATTR_TYPE' => $lang['Attr_type'],
- 'L_ATTR_TYPE_TXT' => $lang['Attr_type_txt'],
- 'L_ATTR_TYPE_IMG' => $lang['Attr_type_img'],
- 'L_ATTR_NAME' => $lang['Attr_name'],
- 'L_ATTR_NAME_EXP' => $lang['Attr_name_exp'],
- 'L_ATTR_IMG' => $lang['Attr_img'],
- 'L_ATTR_IMG_EXP' => $lang['Attr_img_exp'],
- 'L_ATTR_AUTHS' => $lang['Attr_auths'],
- 'L_ATTR_AUTHS_EXP' => $lang['Attr_auths_exp'],
- 'L_ATTR_AUTHS_AUTHOR' => $lang['Attr_auths_author'],
- 'L_ATTR_AUTHS_MOD' => $lang['Attr_auths_mod'],
- 'L_ATTR_AUTHS_ADMIN' => $lang['Attr_auths_admin'],
- 'L_ATTR_DATE' => $lang['Attr_date'],
- 'L_ATTR_DATE_EXP' => $lang['Attr_date_exp'],
- 'L_ATTR_COLOUR' => $lang['Attr_colour'],
- 'L_ATTR_COLOUR_EXP' => $lang['Attr_colour_exp'],
- 'L_ATTR_ORDER' => $lang['Attr_order'],
- // order list
- 'S_ATTR_ORDER' => $attr_list_order,
- // buttons
- 'L_SUBMIT' => $lang['Submit'],
- 'I_SUBMIT' => $get->root . $images['cmd_submit'],
- 'L_CANCEL' => $lang['Cancel'],
- 'I_CANCEL' => $get->root . $images['cmd_cancel'],
- ));
- // call the template file
- $template->set_filenames(array('body' => 'admin/attributes_edit_body.html'));
- break;
- case 'moveup':
- case 'movedw':
- if ( empty($attr_id) || !$attr_id )
- {
- message_die(GENERAL_MESSAGE, 'Must_select_attr');
- }
- $fields = array();
- $fields_inc = array('attr_order' => ($mode == 'movedw') ? + 15 : - 15);
- $db->sql_statement($fields, $fields_inc);
- $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
- SET ' . $db->sql_update . '
- WHERE attr_id = ' . $attr_id;
- $db->sql_query($sql, false, __LINE__, __FILE__);
- $sql = 'SELECT attr_id FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order';
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- while ( $row = $db->sql_fetchrow($result) )
- {
- $fields = array();
- $fields_inc = array('attr_order' => + 10);
- $db->sql_statement($fields, $fields_inc);
- $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
- SET ' . $db->sql_update . '
- WHERE attr_id = ' . (int) $row['attr_id'];
- $db->sql_query($sql, false, __LINE__, __FILE__);
- }
- $db->sql_freeresult($result);
- message_return('Attr_order_updated', 'Click_return_attributes', $requester);
- break;
- case 'save':
- // strip all tags from data ...
- $strip_var_list = array('attr_name', 'attr_img', 'attr_date', 'attr_colour');
- foreach ( $strip_var_list as $value )
- {
- $$value = request_var($value, TYPE_NO_HTML);
- }
- // and these ones too :)
- $integer_var_list = array('attr_type', 'attr_author', 'attr_mod', 'attr_admin', 'attr_tmp_order', 'attr_order');
- foreach ( $integer_var_list as $value )
- {
- $$value = request_var($value, TYPE_INT);
- }
- $attr_order = ( ($attr_order + 10) == $attr_tmp_order ) ? $attr_tmp_order : $attr_order + 5;
- if ( empty($attr_name) )
- {
- message_die(GENERAL_MESSAGE, 'Attr_error_no_name');
- }
- if ( empty($attr_img) && $attr_type )
- {
- message_die(GENERAL_MESSAGE, 'Attr_error_no_img');
- }
- // make an ary for auths
- $attr_auths_ary = array($attr_author, $attr_mod, $attr_admin);
- $fields = array(
- 'attr_type' => $attr_type,
- 'attr_name' => $attr_name,
- 'attr_img' => $attr_img,
- 'attr_auths' => serialize($attr_auths_ary),
- 'attr_date' => $attr_date,
- 'attr_colour' => $attr_colour,
- 'attr_order' => $attr_order,
- );
- if ( $attr_id )
- {
- $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
- SET ' . $db->sql_fields('update', $fields) . '
- WHERE attr_id = ' . $attr_id;
- $message = 'Attr_updated';
- }
- else
- {
- $new_order = $attr_order - 1;
- $attr_order = ($attr_tmp_order == $new_order) ? $attr_order + 9 : $attr_order;
- unset($fields['attr_order']);
- $fields += array('attr_order' => $attr_order);
- $sql = 'INSERT INTO ' . ATTRIBUTES_TABLE . ' (' . $db->sql_fields('fields', $fields) . ')
- VALUES (' . $db->sql_fields('values', $fields) . ')';
- $message = 'Attr_added';
- }
- $db->sql_query($sql, false, __LINE__, __FILE__);
- if ( $attr_order != $attr_tmp_order )
- {
- $sql = 'SELECT attr_id FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order';
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- while ( $row = $db->sql_fetchrow($result) )
- {
- $fields = array();
- $fields_inc = array('attr_order' => + 10);
- $db->sql_statement($fields, $fields_inc);
- $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
- SET ' . $db->sql_update . '
- WHERE attr_id = ' . (int) $row['attr_id'];
- $db->sql_query($sql, false, __LINE__, __FILE__);
- }
- $db->sql_freeresult($result);
- }
- message_return($message, 'Click_return_attributes', $requester);
- break;
- case 'delete':
- if ( empty($attr_id) || !$attr_id )
- {
- message_die(GENERAL_MESSAGE, 'Must_select_attr');
- }
- $confirm = request_var('confirm', TYPE_NO_HTML);
- if ( $confirm )
- {
- $sql = 'DELETE FROM ' . ATTRIBUTES_TABLE . ' WHERE attr_id = ' . $attr_id;
- $db->sql_query($sql, false, __LINE__, __FILE__);
- $sql = 'SELECT attr_id FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order';
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- while ( $row = $db->sql_fetchrow($result) )
- {
- $fields = array();
- $fields_inc = array('attr_order' => + 10);
- $db->sql_statement($fields, $fields_inc);
- $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
- SET ' . $db->sql_update . '
- WHERE attr_id = ' . (int) $row['attr_id'];
- $db->sql_query($sql, false, __LINE__, __FILE__);
- }
- $db->sql_freeresult($result);
- message_return('Attr_removed', 'Click_return_attributes', $requester);
- }
- else if ( !$confirm )
- {
- confirm_delete($requester, 'Confirm', 'Confirm_delete_attr', array('mode' => 'delete', 'id' => $attr_id));
- }
- else
- {
- message_die(GENERAL_MESSAGE, 'Must_select_attr');
- }
- break;
- default:
- $sql = 'SELECT * FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order ASC';
- $result = $db->sql_query($sql, false, __LINE__, __FILE__);
- $row = $db->sql_fetchrowset($result);
- $count = $db->sql_numrows($result);
- $color = false;
- for ( $i = 0; $i < $count; $i++ )
- {
- $color = !$color;
- $template->assign_block_vars('row', array(
- 'ATTR_NAME' => lng_key($row[$i]['attr_name']),
- 'ATTR_IMG' => img_key($row[$i]['attr_image']),
- 'ATTR_COLOUR' => $row[$i]['attr_colour'],
- 'ATTR_DATE' => $row[$i]['attr_date'],
- 'ATTR_GET_COLOUR' => get_colour($row[$i]['attr_colour']),
- 'U_MOVEUP' => $get->url($requester, array('mode' => 'moveup', 'id' => $row[$i]['attr_id']), true),
- 'U_MOVEDW' => $get->url($requester, array('mode' => 'movedw', 'id' => $row[$i]['attr_id']), true),
- 'U_EDIT' => $get->url($requester, array('mode' => 'edit', 'id' => $row[$i]['attr_id']), true),
- 'U_DELETE' => $get->url($requester, array('mode' => 'delete', 'id' => $row[$i]['attr_id']), true),
- ));
- $switch_ary = array(
- 'light' => $color,
- 'type' => !$row[$i]['attr_type'],
- 'type.colour' => !empty($row[$i]['attr_colour']),
- 'colour' => !empty($row[$i]['attr_colour']),
- 'date' => !empty($row[$i]['attr_date']),
- );
- _switch_build($switch_ary, 'row');
- // display the auths
- $attr_auths = unserialize($row[$i]['attr_auths']);
- $attr_auths_count = count($attr_auths);
- $attr_auths_levels = array($lang['Attr_auths_author'], $lang['Attr_auths_mod'], $lang['Attr_auths_admin']);
- for ( $j = 0; $j < $attr_auths_count; $j++ )
- {
- if ( !empty($attr_auths[$j]) )
- {
- $template->assign_block_vars('row.auths', array('ATTR_AUTHS' => $attr_auths_levels[$j]));
- $get->assign_switch('row.auths.sep', $j < ($attr_auths_count - 1));
- }
- }
- }
- // send to template
- $template->assign_vars(array(
- 'S_REQUESTER' => $get->url($requester, '', true),
- 'L_TITLE' => $lang['Attributes'],
- 'L_EXPLAIN' => $lang['Attributes_exp'],
- 'L_ATTR_NAME' => $lang['Attr_name'],
- 'L_ATTR_COLOUR' => $lang['Attr_colour'],
- 'L_ATTR_AUTHS' => $lang['Attr_auths'],
- 'L_ATTR_DATE' => $lang['Attr_date'],
- 'L_ACTION' => $lang['Action'],
- // none
- 'L_ATTR_NONE' => $lang['Attr_none'],
- 'L_ATTR_UNDEFINED' => $lang['Attr_undefined'],
- // buttons
- 'L_MOVEUP' => $lang['Move_up'],
- 'I_MOVEUP' => $get->root . $images['cmd_up_arrow'],
- 'L_MOVEDW' => $lang['Move_down'],
- 'I_MOVEDW' => $get->root . $images['cmd_down_arrow'],
- 'L_EDIT' => $lang['Edit'],
- 'I_EDIT' => $get->root . $images['cmd_edit'],
- 'L_DELETE' => $lang['Delete'],
- 'I_DELETE' => $get->root . $images['cmd_delete'],
- // add new attribute
- 'U_ADD' => $get->url($requester, array('mode' => 'add'), true),
- 'L_ADD' => $lang['Add'],
- 'I_ADD' => $get->root . $images['cmd_add'],
- ));
- // call the template file
- $template->set_filenames(array('body' => 'admin/attributes_list_body.html'));
- break;
- }
- // display the page
- $template->pparse('body');
- include($get->url('admin/page_footer_admin'));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement