Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.20 KB | None | 0 0
  1. <?php
  2. //
  3. //  file: acp/acp_attributes.php
  4. //  author: Adrien BONNEL
  5. //  begin: 10/06/2010
  6. //  version: 0.0.3 - 10/08/2010
  7. //
  8.  
  9. // secure this file !
  10. define('IN_PHPBB', true);
  11.  
  12. // show the menu !
  13. if ( !empty($setmodules) )
  14. {
  15.     $file = basename(__FILE__);
  16.     $module['01_General']['03_Attributes'] = $file;
  17.  
  18.     return;
  19. }
  20.  
  21. // header
  22. $phpbb_root_path = './../';
  23. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  24. $requester = 'admin/admin_attributes';
  25. require('./pagestart.' . $phpEx);
  26.  
  27. // get parameters
  28. $cancel = request_var('cancel', TYPE_NO_HTML);
  29. $mode = request_var('mode', TYPE_NO_HTML);
  30. $no_page_header = $cancel;
  31.  
  32. // define $mode with additional parameters
  33. $mode = _butt('submit_form') ? 'save' : ( _butt('cancel_form') ? '' : $mode);
  34. $mode = !empty($cancel) ? '' : $mode;
  35.  
  36. // initialization
  37. $attr_id = request_var('id', TYPE_INT);
  38.  
  39. // define a function for the order
  40. function attr_select_order($attr_order, $attr_id, $attr_tmp_order, $select)
  41. {
  42.     global $db, $lang;
  43.  
  44.     $sql_where = !empty($select) ? ' WHERE attr_id <> ' . (int) $attr_id : '';
  45.     $sql_order = !empty($attr_order) ? ' ORDER BY ' . $attr_order : '';
  46.  
  47.     $sql = 'SELECT * FROM ' . ATTRIBUTES_TABLE . $sql_where . $sql_order;
  48.     $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  49.  
  50.     $this_order = $attr_tmp_order - 10;
  51.     $attr_list_order = '<option value="0">' . $lang['Top'] . '</option>';
  52.     while ( $row = $db->sql_fetchrow($result) )
  53.     {
  54.         $selected = ($row['attr_order'] == $this_order) ? ' selected="selected"' : '';
  55.         $attr_list_order .= '<option value="' . $row['attr_order'] . '" style="font-weight:bold;"' . $selected . '>' . lng_key($row['attr_name']) . '</option>';
  56.     }
  57.  
  58.     return $attr_list_order;
  59. }
  60.  
  61. // just do it !
  62. switch ( $mode )
  63. {
  64.     case 'add':
  65.     case 'edit':
  66.  
  67.         if ( $mode == 'edit' )
  68.         {
  69.             if ( empty($attr_id) )
  70.             {
  71.                 message_die(GENERAL_MESSAGE, 'Must_select_attr');
  72.             }
  73.  
  74.             $sql = 'SELECT * FROM ' . ATTRIBUTES_TABLE . ' WHERE attr_id = ' . $attr_id;
  75.             $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  76.             $row = $db->sql_fetchrow($result);
  77.             $tmp_order = $row['attr_order'];
  78.  
  79.             // generate the list
  80.             $attr_list_order = attr_select_order('attr_order', $attr_id, $row['attr_order'], true);
  81.  
  82.             // hidden fields
  83.             _hide_build(array('id' => $attr_id, 'attr_tmp_order' => $row['attr_order']));
  84.  
  85.             $template->assign_vars(array(
  86.                 'L_TITLE' => $lang['Attr_edit'],
  87.                 'L_EXPLAIN' => $lang['Attr_edit_exp'],
  88.  
  89.                 'ATTR_NAME' => $row['attr_name'],
  90.                 'ATTR_IMG' => $row['attr_img'],
  91.                 'ATTR_DATE' => $row['attr_date'],
  92.                 'ATTR_COLOUR' => $row['attr_colour'],
  93.             ));
  94.             $get->assign_switch('img_type', $row['attr_type']);
  95.  
  96.             // checks the auths
  97.             $attr_auths_ary = unserialize($row['attr_auths']);
  98.             $attr_auths_ary_switch = array('attr_author', 'attr_mod', 'attr_admin');
  99.             $attr_auths_ary_count = count($attr_auths_ary);
  100.  
  101.             for ( $i = 0; $i < $attr_auths_ary_count; $i++ )
  102.             {
  103.                 $get->assign_switch($attr_auths_ary_switch[$i], !empty($attr_auths_ary[$i]));
  104.             }
  105.         }
  106.         else
  107.         {
  108.             $sql = 'SELECT attr_id, attr_order FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order DESC LIMIT 1';
  109.             $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  110.             $row = $db->sql_fetchrow($result);
  111.  
  112.             // generate the list
  113.             $attr_list_order = attr_select_order('attr_order', $row['attr_id'], $row['attr_order'], 0);
  114.  
  115.             // hidden fields
  116.             _hide_build(array('attr_tmp_order' => $row['attr_order']));
  117.  
  118.             // increment this value
  119.             $row['attr_order'] += 10;
  120.  
  121.             $template->assign_vars(array(
  122.                 'L_TITLE' => $lang['Attr_add'],
  123.                 'L_EXPLAIN' => $lang['Attr_add_exp'],
  124.             ));
  125.         }
  126.  
  127.         // send hidden fields to template
  128.         _hide_send();
  129.  
  130.         // send to template
  131.         $template->assign_vars(array(
  132.             'S_REQUESTER' => $get->url($requester, '', true),
  133.  
  134.             'L_ATTR_TYPE' => $lang['Attr_type'],
  135.             'L_ATTR_TYPE_TXT' => $lang['Attr_type_txt'],
  136.             'L_ATTR_TYPE_IMG' => $lang['Attr_type_img'],
  137.             'L_ATTR_NAME' => $lang['Attr_name'],
  138.             'L_ATTR_NAME_EXP' => $lang['Attr_name_exp'],
  139.             'L_ATTR_IMG' => $lang['Attr_img'],
  140.             'L_ATTR_IMG_EXP' => $lang['Attr_img_exp'],
  141.             'L_ATTR_AUTHS' => $lang['Attr_auths'],
  142.             'L_ATTR_AUTHS_EXP' => $lang['Attr_auths_exp'],
  143.             'L_ATTR_AUTHS_AUTHOR' => $lang['Attr_auths_author'],
  144.             'L_ATTR_AUTHS_MOD' => $lang['Attr_auths_mod'],
  145.             'L_ATTR_AUTHS_ADMIN' => $lang['Attr_auths_admin'],
  146.             'L_ATTR_DATE' => $lang['Attr_date'],
  147.             'L_ATTR_DATE_EXP' => $lang['Attr_date_exp'],
  148.             'L_ATTR_COLOUR' => $lang['Attr_colour'],
  149.             'L_ATTR_COLOUR_EXP' => $lang['Attr_colour_exp'],
  150.             'L_ATTR_ORDER' => $lang['Attr_order'],
  151.  
  152.             // order list
  153.             'S_ATTR_ORDER' => $attr_list_order,
  154.  
  155.             // buttons
  156.             'L_SUBMIT' => $lang['Submit'],
  157.             'I_SUBMIT' => $get->root . $images['cmd_submit'],
  158.             'L_CANCEL' => $lang['Cancel'],
  159.             'I_CANCEL' => $get->root . $images['cmd_cancel'],
  160.         ));
  161.  
  162.         // call the template file
  163.         $template->set_filenames(array('body' => 'admin/attributes_edit_body.html'));
  164.  
  165.     break;
  166.  
  167.     case 'moveup':
  168.     case 'movedw':
  169.  
  170.         if ( empty($attr_id) || !$attr_id )
  171.         {
  172.             message_die(GENERAL_MESSAGE, 'Must_select_attr');
  173.         }
  174.  
  175.         $fields = array();
  176.         $fields_inc = array('attr_order' => ($mode == 'movedw') ? + 15 : - 15);
  177.         $db->sql_statement($fields, $fields_inc);
  178.         $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
  179.             SET ' . $db->sql_update . '
  180.             WHERE attr_id = ' . $attr_id;
  181.         $db->sql_query($sql, false, __LINE__, __FILE__);
  182.  
  183.         $sql = 'SELECT attr_id FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order';
  184.         $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  185.  
  186.         while ( $row = $db->sql_fetchrow($result) )
  187.         {
  188.             $fields = array();
  189.             $fields_inc = array('attr_order' => + 10);
  190.             $db->sql_statement($fields, $fields_inc);
  191.             $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
  192.                 SET ' . $db->sql_update . '
  193.                 WHERE attr_id = ' . (int) $row['attr_id'];
  194.             $db->sql_query($sql, false, __LINE__, __FILE__);
  195.         }
  196.         $db->sql_freeresult($result);
  197.  
  198.         message_return('Attr_order_updated', 'Click_return_attributes', $requester);
  199.  
  200.     break;
  201.  
  202.     case 'save':
  203.  
  204.         // strip all tags from data ...
  205.         $strip_var_list = array('attr_name', 'attr_img', 'attr_date', 'attr_colour');
  206.         foreach ( $strip_var_list as $value )
  207.         {
  208.             $$value = request_var($value, TYPE_NO_HTML);
  209.         }
  210.  
  211.         // and these ones too :)
  212.         $integer_var_list = array('attr_type', 'attr_author', 'attr_mod', 'attr_admin', 'attr_tmp_order', 'attr_order');
  213.         foreach ( $integer_var_list as $value )
  214.         {
  215.             $$value = request_var($value, TYPE_INT);
  216.         }
  217.         $attr_order = ( ($attr_order + 10) == $attr_tmp_order ) ? $attr_tmp_order : $attr_order + 5;
  218.  
  219.         if ( empty($attr_name) )
  220.         {
  221.             message_die(GENERAL_MESSAGE, 'Attr_error_no_name');
  222.         }
  223.  
  224.         if ( empty($attr_img) && $attr_type )
  225.         {
  226.             message_die(GENERAL_MESSAGE, 'Attr_error_no_img');
  227.         }
  228.  
  229.         // make an ary for auths
  230.         $attr_auths_ary = array($attr_author, $attr_mod, $attr_admin);
  231.  
  232.         $fields = array(
  233.             'attr_type' => $attr_type,
  234.             'attr_name' => $attr_name,
  235.             'attr_img' => $attr_img,
  236.             'attr_auths' => serialize($attr_auths_ary),
  237.             'attr_date' => $attr_date,
  238.             'attr_colour' => $attr_colour,
  239.             'attr_order' => $attr_order,
  240.         );
  241.  
  242.         if ( $attr_id )
  243.         {
  244.             $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
  245.                 SET ' . $db->sql_fields('update', $fields) . '
  246.                 WHERE attr_id = ' . $attr_id;
  247.             $message = 'Attr_updated';
  248.         }
  249.         else
  250.         {
  251.             $new_order = $attr_order - 1;
  252.             $attr_order = ($attr_tmp_order == $new_order) ? $attr_order + 9 : $attr_order;
  253.  
  254.             unset($fields['attr_order']);
  255.             $fields += array('attr_order' => $attr_order);
  256.  
  257.             $sql = 'INSERT INTO ' . ATTRIBUTES_TABLE . ' (' . $db->sql_fields('fields', $fields) . ')
  258.                 VALUES (' . $db->sql_fields('values', $fields) . ')';
  259.             $message = 'Attr_added';
  260.         }
  261.         $db->sql_query($sql, false, __LINE__, __FILE__);
  262.  
  263.         if ( $attr_order != $attr_tmp_order )
  264.         {
  265.             $sql = 'SELECT attr_id FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order';
  266.             $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  267.  
  268.             while ( $row = $db->sql_fetchrow($result) )
  269.             {
  270.                 $fields = array();
  271.                 $fields_inc = array('attr_order' => + 10);
  272.                 $db->sql_statement($fields, $fields_inc);
  273.                 $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
  274.                     SET ' . $db->sql_update . '
  275.                     WHERE attr_id = ' . (int) $row['attr_id'];
  276.                 $db->sql_query($sql, false, __LINE__, __FILE__);
  277.             }
  278.             $db->sql_freeresult($result);
  279.         }
  280.  
  281.         message_return($message, 'Click_return_attributes', $requester);
  282.  
  283.     break;
  284.  
  285.     case 'delete':
  286.  
  287.         if ( empty($attr_id) || !$attr_id )
  288.         {
  289.             message_die(GENERAL_MESSAGE, 'Must_select_attr');
  290.         }
  291.  
  292.         $confirm = request_var('confirm', TYPE_NO_HTML);
  293.  
  294.         if ( $confirm )
  295.         {
  296.             $sql = 'DELETE FROM ' . ATTRIBUTES_TABLE . ' WHERE attr_id = ' . $attr_id;
  297.             $db->sql_query($sql, false, __LINE__, __FILE__);
  298.  
  299.             $sql = 'SELECT attr_id FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order';
  300.             $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  301.  
  302.             while ( $row = $db->sql_fetchrow($result) )
  303.             {
  304.                 $fields = array();
  305.                 $fields_inc = array('attr_order' => + 10);
  306.                 $db->sql_statement($fields, $fields_inc);
  307.                 $sql = 'UPDATE ' . ATTRIBUTES_TABLE . '
  308.                     SET ' . $db->sql_update . '
  309.                     WHERE attr_id = ' . (int) $row['attr_id'];
  310.                 $db->sql_query($sql, false, __LINE__, __FILE__);
  311.             }
  312.             $db->sql_freeresult($result);
  313.  
  314.             message_return('Attr_removed', 'Click_return_attributes', $requester);
  315.         }
  316.         else if ( !$confirm )
  317.         {
  318.             confirm_delete($requester, 'Confirm', 'Confirm_delete_attr', array('mode' => 'delete', 'id' => $attr_id));
  319.         }
  320.         else
  321.         {
  322.             message_die(GENERAL_MESSAGE, 'Must_select_attr');
  323.         }
  324.  
  325.     break;
  326.  
  327.     default:
  328.  
  329.         $sql = 'SELECT * FROM ' . ATTRIBUTES_TABLE . ' ORDER BY attr_order ASC';
  330.         $result = $db->sql_query($sql, false, __LINE__, __FILE__);
  331.         $row = $db->sql_fetchrowset($result);
  332.         $count = $db->sql_numrows($result);
  333.  
  334.         $color = false;
  335.         for ( $i = 0; $i < $count; $i++ )
  336.         {
  337.             $color = !$color;
  338.             $template->assign_block_vars('row', array(
  339.                 'ATTR_NAME' => lng_key($row[$i]['attr_name']),
  340.                 'ATTR_IMG' => img_key($row[$i]['attr_image']),
  341.                 'ATTR_COLOUR' => $row[$i]['attr_colour'],
  342.                 'ATTR_DATE' => $row[$i]['attr_date'],
  343.  
  344.                 'ATTR_GET_COLOUR' => get_colour($row[$i]['attr_colour']),
  345.  
  346.                 'U_MOVEUP' => $get->url($requester, array('mode' => 'moveup', 'id' => $row[$i]['attr_id']), true),
  347.                 'U_MOVEDW' => $get->url($requester, array('mode' => 'movedw', 'id' => $row[$i]['attr_id']), true),
  348.                 'U_EDIT' => $get->url($requester, array('mode' => 'edit', 'id' => $row[$i]['attr_id']), true),
  349.                 'U_DELETE' => $get->url($requester, array('mode' => 'delete', 'id' => $row[$i]['attr_id']), true),
  350.             ));
  351.             $switch_ary = array(
  352.                 'light' => $color,
  353.                 'type' => !$row[$i]['attr_type'],
  354.                 'type.colour' => !empty($row[$i]['attr_colour']),
  355.                 'colour' => !empty($row[$i]['attr_colour']),
  356.                 'date' => !empty($row[$i]['attr_date']),
  357.             );
  358.             _switch_build($switch_ary, 'row');
  359.  
  360.             // display the auths
  361.             $attr_auths = unserialize($row[$i]['attr_auths']);
  362.             $attr_auths_count = count($attr_auths);
  363.             $attr_auths_levels = array($lang['Attr_auths_author'], $lang['Attr_auths_mod'], $lang['Attr_auths_admin']);
  364.  
  365.             for ( $j = 0; $j < $attr_auths_count; $j++ )
  366.             {
  367.                 if ( !empty($attr_auths[$j]) )
  368.                 {
  369.                     $template->assign_block_vars('row.auths', array('ATTR_AUTHS' => $attr_auths_levels[$j]));
  370.                     $get->assign_switch('row.auths.sep', $j < ($attr_auths_count - 1));
  371.                 }
  372.             }
  373.         }
  374.  
  375.         // send to template
  376.         $template->assign_vars(array(
  377.             'S_REQUESTER' => $get->url($requester, '', true),
  378.  
  379.             'L_TITLE' => $lang['Attributes'],
  380.             'L_EXPLAIN' => $lang['Attributes_exp'],
  381.  
  382.             'L_ATTR_NAME' => $lang['Attr_name'],
  383.             'L_ATTR_COLOUR' => $lang['Attr_colour'],
  384.             'L_ATTR_AUTHS' => $lang['Attr_auths'],
  385.             'L_ATTR_DATE' => $lang['Attr_date'],
  386.             'L_ACTION' => $lang['Action'],
  387.  
  388.             // none
  389.             'L_ATTR_NONE' => $lang['Attr_none'],
  390.             'L_ATTR_UNDEFINED' => $lang['Attr_undefined'],
  391.  
  392.             // buttons
  393.             'L_MOVEUP' => $lang['Move_up'],
  394.             'I_MOVEUP' => $get->root . $images['cmd_up_arrow'],
  395.             'L_MOVEDW' => $lang['Move_down'],
  396.             'I_MOVEDW' => $get->root . $images['cmd_down_arrow'],
  397.             'L_EDIT' => $lang['Edit'],
  398.             'I_EDIT' => $get->root . $images['cmd_edit'],
  399.             'L_DELETE' => $lang['Delete'],
  400.             'I_DELETE' => $get->root . $images['cmd_delete'],
  401.  
  402.             // add new attribute
  403.             'U_ADD' => $get->url($requester, array('mode' => 'add'), true),
  404.             'L_ADD' => $lang['Add'],
  405.             'I_ADD' => $get->root . $images['cmd_add'],
  406.         ));
  407.  
  408.         // call the template file
  409.         $template->set_filenames(array('body' => 'admin/attributes_list_body.html'));
  410.  
  411.     break;
  412. }
  413.  
  414. // display the page
  415. $template->pparse('body');
  416. include($get->url('admin/page_footer_admin'));
  417.  
  418. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement