[ PHPXref.com ] [ Generated: Sun Jul 20 18:37:24 2008 ] [ MetaBB 5.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> adr_character_inventory.php (source)

   1  <?php 
   2  /***************************************************************************

   3   *                    adr_character_inventory.php

   4   *                ------------------------

   5   *    begin             : 09/02/2004

   6   *    copyright            : Malicious Rabbit / Dr DLP

   7   *

   8   *

   9   ***************************************************************************/
  10  
  11  /***************************************************************************

  12   *

  13   *   This program is free software; you can redistribute it and/or modify

  14   *   it under the terms of the GNU General Public License as published by

  15   *   the Free Software Foundation; either version 2 of the License, or

  16   *   (at your option) any later version.

  17   *

  18   *

  19   ***************************************************************************/
  20  
  21  define('IN_PHPBB', true); 
  22  define('IN_ADR_BATTLE', true);
  23  define('IN_ADR_SHOPS', true); 
  24  define('IN_ADR_CHARACTER', true); 
  25  $phpbb_root_path = './'; 
  26  include ($phpbb_root_path . 'extension.inc'); 
  27  include($phpbb_root_path . 'common.'.$phpEx);
  28  
  29  $loc = 'character';
  30  $sub_loc = 'adr_character_inventory';
  31  
  32  //

  33  // Start session management

  34  $userdata = session_pagestart($user_ip, PAGE_INDEX); 
  35  init_userprefs($userdata); 
  36  // End session management

  37  //

  38  
  39  include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
  40  
  41  $user_id = $userdata['user_id'];
  42  
  43  // Sorry , only logged users ...

  44  if ( !$userdata['session_logged_in'] )
  45  {
  46      $redirect = "adr_character_inventory.$phpEx";
  47      $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
  48      header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
  49  }
  50  
  51  include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  52  
  53  // Get the general config

  54  $adr_general = adr_get_general_config();
  55  
  56  adr_enable_check();
  57  adr_ban_check($user_id);
  58  adr_character_created_check($user_id);
  59  
  60  if ( (!( isset($HTTP_POST_VARS[POST_USERS_URL]) || isset($HTTP_GET_VARS[POST_USERS_URL]))) || ( empty($HTTP_POST_VARS[POST_USERS_URL]) && empty($HTTP_GET_VARS[POST_USERS_URL])))
  61  { 
  62      $view_userdata = $userdata; 
  63  } 
  64  else 
  65  { 
  66      $view_userdata = get_userdata(intval($HTTP_GET_VARS[POST_USERS_URL])); 
  67  } 
  68  $searchid = $view_userdata['user_id'];
  69  $colspan = 8;
  70  
  71  $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  72  
  73  if ( isset($HTTP_GET_VARS['mode2']) || isset($HTTP_POST_VARS['mode2']) )
  74  {
  75      $mode2 = ( isset($HTTP_POST_VARS['mode2']) ) ? htmlspecialchars($HTTP_POST_VARS['mode2']) : htmlspecialchars($HTTP_GET_VARS['mode2']);
  76  }
  77  else
  78  {
  79      $mode2 = 'itemname';
  80  }
  81  
  82  if(isset($HTTP_POST_VARS['order']))
  83  {
  84      $sort_order = ($HTTP_POST_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
  85  }
  86  else if(isset($HTTP_GET_VARS['order']))
  87  {
  88      $sort_order = ($HTTP_GET_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
  89  }
  90  else
  91  {
  92      $sort_order = 'ASC';
  93  }
  94  
  95  $mode_types_text = array( $lang['Adr_shops_categories_item_name'] , $lang['Adr_items_price'] , $lang['Adr_items_type_use'] , $lang['Adr_items_quality'] , $lang['Adr_items_power'] , $lang['Adr_items_duration']);
  96  $mode_types = array( 'name', 'price' , 'type' , 'quality' , 'power' , 'duration' );
  97  
  98  $select_sort_mode = '<select name="mode2">';
  99  for($i = 0; $i < count($mode_types_text); $i++)
 100  {
 101      $selected = ( $mode2 == $mode_types[$i] ) ? ' selected="selected"' : '';
 102      $select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
 103  }
 104  $select_sort_mode .= '</select>';
 105  
 106  $select_sort_order = '<select name="order">';
 107  if($sort_order == 'ASC')
 108  {
 109      $select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
 110  }
 111  else
 112  {
 113      $select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
 114  }
 115  $select_sort_order .= '</select>';
 116  
 117  switch( $mode2 )
 118  {
 119      case 'name':
 120          $order_by = "i.item_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 121          break;
 122      case 'price':
 123          $order_by = "i.item_price $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 124          break;
 125      case 'type':
 126          $order_by = "i.item_type_use $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 127          break;
 128      case 'quality':
 129          $order_by = "i.item_quality $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 130          break;
 131      case 'power':
 132          $order_by = "i.item_power $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 133          break;
 134      case 'duration':
 135          $order_by = "i.item_duration $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 136          break;
 137      default:
 138          $order_by = "i.item_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
 139          break;
 140  }
 141  
 142  if ( isset($HTTP_GET_VARS['cat']) || isset($HTTP_POST_VARS['cat']) )
 143  {
 144      $cat = ( isset($HTTP_POST_VARS['cat']) ) ? htmlspecialchars($HTTP_POST_VARS['cat']) : htmlspecialchars($HTTP_GET_VARS['cat']);
 145  }
 146  else
 147  {
 148      $cat = 0;
 149  }
 150  $cat_sql = ( $cat ) ? 'AND i.item_type_use = '.$cat : '';
 151  $categories_text = array( Adr_items_type_all , Adr_items_type_raw_materials , Adr_items_type_rare_raw_materials , Adr_items_type_tools_pickaxe , Adr_items_type_tools_magictome , Adr_items_type_weapon , Adr_items_type_enchanted_weapon , Adr_items_type_armor , Adr_items_type_buckler , Adr_items_type_helm , Adr_items_type_gloves , Adr_items_type_magic_attack , Adr_items_type_magic_defend , Adr_items_type_amulet , Adr_items_type_ring , Adr_items_type_health_potion , Adr_items_type_mana_potion , Adr_items_type_misc );
 152  $categories = array( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17);
 153  $select_category = '<select name="cat">';
 154  for($i = 0; $i < count($categories_text); $i++)
 155  {
 156      $selected = ( $cat == $categories[$i] ) ? ' selected="selected"' : '';
 157      $select_category .= '<option value="' . $categories[$i] . '"' . $selected . '>' .$lang[$categories_text[$i]] . '</option>';
 158  }
 159  $select_category .= '</select>';
 160  
 161  
 162  if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
 163  {
 164      $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
 165      $mode = htmlspecialchars($mode);
 166  }
 167  else
 168  {
 169      $mode = "";
 170  }
 171  
 172  if ( $mode != "" )
 173  {
 174      // Prevent some jokes ...

 175      if ( $user_id != $searchid )
 176      {
 177          adr_previous( Adr_not_authed , adr_character_inventory , '' );
 178      }
 179  
 180      switch($mode)
 181      {
 182          case 'delete' :
 183  
 184              // Define some values

 185              $items = ( isset($HTTP_POST_VARS['item_box']) ) ?  $HTTP_POST_VARS['item_box'] : array();
 186  
 187              // Deny deletion  if the user is in a battle

 188              $sql = "SELECT battle_id FROM  " . ADR_BATTLE_LIST_TABLE . "
 189                  WHERE battle_challenger_id = '$user_id'
 190                  AND battle_result = '0'
 191                  AND battle_type = '1'";
 192              if(!($result = $db->sql_query($sql))){
 193                  message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);}
 194              $bat = $db->sql_fetchrow($result);
 195              if(is_numeric($bat['battle_id']))
 196                  adr_previous(Adr_battle_no_delete_items, adr_character_inventory, '');
 197  
 198              $item_id_list .= '(';
 199              if ( count($items) > 0 )
 200              {    
 201                  for($i = 0; $i < count($items); $i++)
 202                  {
 203                         $item_id_list .= $items[$i].',';
 204                  }
 205              }
 206              $item_id_list .= '0)';
 207  
 208              $sql = "DELETE FROM " . ADR_SHOPS_ITEMS_TABLE ."
 209                  WHERE item_owner_id = $user_id 
 210                  AND item_id IN $item_id_list
 211                  AND item_in_shop = 0 ";
 212              if( !$db->sql_query($sql) )
 213              {
 214                  message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
 215              }
 216      
 217              adr_previous( Adr_shop_items_successful_deleted , adr_character_inventory , '' );
 218              break;
 219  
 220          case 'edit' :
 221  
 222              adr_template_file('adr_inventory_edit_body.tpl');
 223  
 224              // Define some values

 225              $items = ( isset($HTTP_POST_VARS['item_box']) ) ?  $HTTP_POST_VARS['item_box'] : array();
 226  
 227              if ( count($items) > 0 )
 228              {    
 229                  for($i = 0; $i < count($items); $i++)
 230                  {
 231                         $item_id = $items[$i];
 232                  }
 233              }
 234  
 235              $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE ."
 236                  WHERE item_id = $item_id 
 237                  AND item_owner_id = $user_id ";
 238              $result = $db->sql_query($sql);
 239              if( !$result )
 240              {
 241                  adr_previous( Adr_shop_items_failure_deleted , adr_character_inventory , '');
 242              }
 243              $items = $db->sql_fetchrow($result);
 244  
 245              $s_hidden_fields = '<input type="hidden" name="mode" value="save_item" /><input type="hidden" name="item_id" value="' . $item_id . '" />';
 246  
 247              $template->assign_vars(array(
 248                  "ITEM_NAME" => adr_get_lang($items['item_name']),
 249                  "ITEM_DESC" => adr_get_lang($items['item_desc']),
 250                  "ITEM_PRICE" => $items['item_price'],
 251                  "L_POINTS" => get_reward_name(),
 252                  "L_NAME" => $lang['Adr_races_name'],
 253                  "L_DESC" => $lang['Adr_races_desc'],
 254                  "L_ITEM_PRICE" => $lang['Adr_items_price'],
 255                  "L_ITEM_EDITION" => sprintf($lang['Adr_items_edition'],adr_get_lang($items['item_name'])),
 256                  "L_SUBMIT" => $lang['Submit'],
 257                  "S_ITEMS_ACTION" => append_sid("adr_character_inventory.$phpEx"),
 258                  "S_HIDDEN_FIELDS" => $s_hidden_fields, 
 259              ));
 260  
 261          break;
 262  
 263          case 'give' :
 264  
 265              adr_template_file('adr_inventory_give_body.tpl');
 266  
 267              $s_hidden_fields = '<input type="hidden" name="mode" value="give_item" />';
 268              $s_hidden_fields .= '<input type="hidden" name="cat" value="'.$cat.'" />';
 269  
 270              // Deny donations if the user is in a battle

 271              $sql = "SELECT battle_id FROM  " . ADR_BATTLE_LIST_TABLE . "
 272                  WHERE battle_challenger_id = '$user_id'
 273                  AND battle_result = '0'
 274                  AND battle_type = '1'";
 275              if(!($result = $db->sql_query($sql))){
 276                  message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);}
 277              $bat = $db->sql_fetchrow($result);
 278              if(is_numeric($bat['battle_id']))
 279                  adr_previous(Adr_battle_no_give_items, adr_character_inventory, '');
 280  
 281              // Define some values

 282              $items = ( isset($HTTP_POST_VARS['item_box']) ) ?  $HTTP_POST_VARS['item_box'] : array();
 283  
 284              $item_id_list .= '(';
 285              if ( count($items) > 0 )
 286              {    
 287                  for($i = 0; $i < count($items); $i++)
 288                  {
 289                         $item_id_list .= $items[$i].',';
 290                  }
 291              }
 292              $item_id_list .= '0)';
 293  
 294              $sql = "SELECT i.* FROM " . ADR_SHOPS_ITEMS_TABLE . " i
 295                  WHERE i.item_owner_id = $user_id
 296                  AND i.item_in_shop = 0
 297                  AND i.item_duration > 0 
 298                  AND i.item_id IN $item_id_list 
 299                  ORDER BY i.item_name ";
 300              if( !($result = $db->sql_query($sql)) )
 301              {
 302                  message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
 303              }
 304              $items = $db->sql_fetchrowset($result);
 305  
 306              $items_name = '';
 307              while( list(,$item) = @each($items) )
 308              {
 309                  $item_id = $item['item_id'];
 310                  $s_hidden_fields .= '<input type="hidden" name="'.$item_id.'" value="1" />';
 311                  $items_name .= adr_get_lang($item['item_name']);
 312                  $items_name .= '<br />';
 313              }
 314  
 315              $sql = "SELECT u.user_id, u.username, c.character_name, c.character_id FROM " . USERS_TABLE . " u, " . ADR_CHARACTERS_TABLE . " c
 316                  WHERE u.user_id <> $user_id
 317                  AND u.user_id = c.character_id
 318                  ORDER by c.character_name";
 319              if(!($result = $db->sql_query($sql))){
 320                  message_die(GENERAL_ERROR, 'Could not obtain user list', '', __LINE__, __FILE__, $sql);}
 321              $users = $db->sql_fetchrowset($result);
 322  
 323              $give_to = '<select name="give_to">';
 324              for($t = 0; $t < count($users); $t++){
 325                  $give_to .= '<option value = "'.$users[$t]['character_id'].'">' . $users[$t]['character_name'] . '&nbsp;('.$users[$t]['username'].')&nbsp;</option>';}
 326              $give_to .= '</select>';
 327  
 328              $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE ."
 329                  WHERE item_id = $item_id 
 330                  AND item_owner_id = $user_id ";
 331              $result = $db->sql_query($sql);
 332              if( !$result )
 333              {
 334                  adr_previous( Adr_shop_items_failure_deleted , adr_character_inventory , '');
 335              }
 336              $items = $db->sql_fetchrow($result);
 337  
 338              $template->assign_vars(array(
 339                  "GIVE_TO" => $give_to,
 340                  "L_ITEM_DONATION" => sprintf($lang['Adr_items_donation'],'<br />'.$items_name),
 341                  "L_GIVE_TO" => $lang['Adr_items_give_to'],
 342                  "L_SUBMIT" => $lang['Submit'],
 343                  "S_ITEMS_ACTION" => append_sid("adr_character_inventory.$phpEx"),
 344                  "S_HIDDEN_FIELDS" => $s_hidden_fields, 
 345              ));
 346  
 347          break;
 348  
 349          case 'give_item' :
 350  
 351              $to_user_id = ( !empty($HTTP_POST_VARS['give_to']) ) ? $HTTP_POST_VARS['give_to'] : $HTTP_GET_VARS['give_to'];
 352  
 353              // Deny donations if the other user is in a battle

 354              $sql = "SELECT battle_id FROM  " . ADR_BATTLE_LIST_TABLE . "
 355                  WHERE battle_challenger_id = '$to_user_id'
 356                  AND battle_result = '0'
 357                  AND battle_type = '1'";
 358              if(!($result = $db->sql_query($sql))){
 359                  message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);}
 360              $bat = $db->sql_fetchrow($result);
 361              if(is_numeric($bat['battle_id']))
 362                  adr_previous(Adr_battle_no_give_items_2, adr_character_inventory, '');
 363  
 364              $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . " 
 365                  WHERE item_owner_id = $user_id
 366                  AND item_in_shop = 0
 367                  AND item_duration > 0 ";
 368              if( !($result = $db->sql_query($sql)) )
 369              {
 370                  message_die(GENERAL_ERROR, $lang['Adr_shop_items_failure_deleted']);
 371              }
 372              $items = $db->sql_fetchrowset($result);
 373  
 374              while( list(,$item) = @each($items) )
 375              {
 376                  if ( isset($HTTP_POST_VARS[$item['item_id']]))
 377                  {
 378                      $item_id = $item['item_id'];
 379                      adr_give_item($user_id , $to_user_id , $item_id  );
 380                  }
 381              }
 382  
 383              adr_previous( Adr_give_item_success , adr_character_inventory , '' );
 384  
 385          break;
 386  
 387          case "save_item":
 388  
 389              $item_id = intval($HTTP_POST_VARS['item_id']);
 390              $item_desc = ( isset($HTTP_POST_VARS['item_desc']) ) ? trim($HTTP_POST_VARS['item_desc']) : trim($HTTP_GET_VARS['item_desc']);
 391              $item_price = intval($HTTP_POST_VARS['item_price']);
 392  
 393                  if ( $item_price >= 0 )
 394                   { 
 395                  $sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE . "
 396                      SET item_desc = '" . str_replace("\'", "''", $item_desc) . "',
 397                          item_price = $item_price
 398                      WHERE item_id = " . $item_id . "
 399                      AND item_owner_id = $user_id ";
 400                  if( !($result = $db->sql_query($sql)) )
 401                  {
 402                      message_die(GENERAL_ERROR, $lang['Adr_shop_items_failure_deleted']);
 403                  }
 404                  }
 405                    else
 406                   {   
 407                          message_die(GENERAL_ERROR, 'Negative amounts are not allowed');            
 408                   }
 409  
 410              adr_previous( Adr_inventory_items_successful_edited , adr_character_inventory , '' );
 411  
 412          break;
 413  
 414          case 'view_item' :
 415  
 416              adr_template_file('adr_inventory_body.tpl');
 417              $template->assign_block_vars('view_item',array());
 418  
 419              $item_owner_id = intval($HTTP_GET_VARS['item_owner_id']);
 420              $item_id = intval($HTTP_GET_VARS['item_id']);
 421  
 422              // All item info

 423              $sql = "SELECT i.* , q.item_quality_lang , t.item_type_lang , e.element_img FROM " . ADR_SHOPS_ITEMS_TABLE . " i
 424                  LEFT JOIN " . ADR_SHOPS_ITEMS_QUALITY_TABLE . " q ON ( i.item_quality = q.item_quality_id )
 425                  LEFT JOIN " . ADR_SHOPS_ITEMS_TYPE_TABLE . " t ON ( i.item_type_use = t.item_type_id )
 426                  LEFT JOIN " . ADR_ELEMENTS_TABLE . " e ON ( i.item_element = e.element_id )
 427                  WHERE i.item_id = $item_id
 428                  AND i.item_owner_id = $item_owner_id
 429                  AND i.item_auth = 0 ";
 430              if( !($result = $db->sql_query($sql)) )
 431              {
 432                  message_die(GENERAL_ERROR, 'Could not query users', '', __LINE__, __FILE__, $sql);
 433              }
 434              $row = $db->sql_fetchrow($result);
 435              $item_logo = $row['item_icon'];
 436              $store_owner_id = $row['item_store_id'];
 437  
 438              if ( $row['item_icon'] != '' )
 439              {
 440                  $item_img = '<img src="adr/images/items/'.$item_logo.'">';
 441              }
 442              else
 443              {
 444                  $item_img = '';
 445              }
 446  
 447              if ( $row['element_img'] != '' && $row['item_element'] != 0 )
 448              {
 449                  $element_img = '<img src="adr/images/elements/'. $row['element_img'] .'">';
 450              }
 451              else
 452              {
 453                  $element_img = $lang['Adr_store_element_none'];
 454              }
 455      
 456              // Check if power limit is enabled

 457              if ( $adr_general['item_power_level'] == 1 )
 458              {
 459                  $lang_power = $lang['Adr_store_level'];
 460              }
 461              else
 462              {
 463                  $lang_power = $lang['Adr_store_power'];
 464              }
 465  
 466              $template->assign_vars(array(
 467                  "ROW_CLASS" => $theme['td_class1'],
 468                  "ROW_CLASS_2" => $theme['td_class2'],
 469                  "ACTION_SELECT" => $action_select,
 470                  "ITEM_ID" => $row['item_id'],
 471                  "ITEM_NAME" => adr_get_lang($row['item_name']),
 472                  "ITEM_DESC" => adr_get_lang($row['item_desc']),
 473                  "ITEM_IMG" => $item_img,
 474                  "ITEM_QUALITY" => $lang[$row['item_quality_lang']],
 475                  "ITEM_TYPE" => $lang[$row['item_type_lang']],
 476                  "ITEM_DURA" => $row['item_duration'],
 477                  "ITEM_DURA_MAX" => $row['item_duration_max'],
 478                  "ITEM_POWER" => $row['item_power'],
 479                  "ITEM_PRICE" => $row['item_price'],
 480                  "ITEM_WEIGHT" => $row['item_weight'],
 481                  "ITEM_ELEMENT" => $element_img,
 482                  "ITEM_ADD_POWER" => $row['item_add_power'], 
 483                  "ITEM_MP" => $row['item_mp_use'],
 484                  "ITEM_POINTS" => $points_name,
 485                  "SHOP_OWNER_ID" => $store_owner_id,
 486                  "L_ITEM_INFO" =>     $lang['Adr_store_item'],
 487                  "L_ITEM_NAME" => $lang['Adr_store_name'],
 488                  "L_ITEM_DESC" => $lang['Adr_store_desc'],
 489                  "L_ITEM_QUALITY" => $lang['Adr_store_quality'],
 490                  "L_ITEM_POWER" => $lang_power,
 491                  "L_ITEM_ADD_POWER" => $lang['Adr_items_dex'], 
 492                  "L_ITEM_MP" => $lang['Adr_items_mp_use'], 
 493                  "L_ITEM_DURA" => $lang['Adr_store_duration'],
 494                  "L_ITEM_IMG" => $lang['Adr_races_image'],
 495                  "L_ITEM_PRICE" => $lang['Adr_store_price'],
 496                  "L_ITEM_TYPE" => $lang['Adr_items_type_use'],
 497                  "L_ITEM_WEIGHT" => $lang['Adr_store_weight'],
 498                  "L_ITEM_ELEMENT" => $lang['Adr_store_element'],
 499                  "L_ACTION" => $lang['Adr_items_action'],
 500                  "L_SUBMIT" => $lang['Submit'],
 501              ));
 502  
 503              break;
 504  
 505          case 'sell' :
 506  
 507              // Define some values

 508              $items = ( isset($HTTP_POST_VARS['item_box']) ) ?  $HTTP_POST_VARS['item_box'] : array();
 509  
 510              // Deny sale if the user is in a battle

 511              $sql = "SELECT battle_id FROM  " . ADR_BATTLE_LIST_TABLE . "
 512                  WHERE battle_challenger_id = '$user_id'
 513                  AND battle_result = '0'
 514                  AND battle_type = '1'";
 515              if(!($result = $db->sql_query($sql))){
 516                  message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);}
 517              $bat = $db->sql_fetchrow($result);
 518              if(is_numeric($bat['battle_id']))
 519                  adr_previous(Adr_battle_no_sell_items, adr_character_inventory, '');
 520  
 521              $item_id_list .= '(';
 522              if ( count($items) > 0 )
 523              {    
 524                  for($i = 0; $i < count($items); $i++)
 525                  {
 526                         $item_id_list .= $items[$i].',';
 527                  }
 528              }
 529              $item_id_list .= '0)';
 530  
 531              $sql = "SELECT i.* FROM " . ADR_SHOPS_ITEMS_TABLE . " i
 532                  WHERE i.item_owner_id = $user_id
 533                  AND i.item_in_shop = 0
 534                  AND i.item_duration > 0 
 535                  AND i.item_auth = 0 
 536                  AND i.item_id IN $item_id_list 
 537                  ORDER BY i.item_name ";
 538              if( !($result = $db->sql_query($sql)) )
 539              {
 540                  message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
 541              }
 542              $items = $db->sql_fetchrowset($result);
 543  
 544              $items_name = '';
 545              while( list(,$item) = @each($items) )
 546              {
 547                  $item_id = $item['item_id'];
 548                  $temp_price = adr_get_item_real_price($item_id , $user_id);
 549                  $price = intval($price + adr_use_skill_trading($user_id , $temp_price , sell));
 550                  $s_hidden_fields .= '<input type="hidden" name="'.$item_id.'" value="1" />';
 551              }
 552  
 553              adr_template_file('adr_confirm_body.tpl');
 554  
 555              $template->assign_block_vars('sell_item' , array());
 556  
 557              $s_hidden_fields .= '<input type="hidden" name="cat" value="'.$cat.'" />';
 558              $s_hidden_fields .= '<input type="hidden" name="mode" value="sell_item" />';
 559  
 560              $template->assign_vars(array(
 561                  'MESSAGE_TITLE' => $lang['Adr_items_sell_confirm'],
 562                  'MESSAGE_TEXT' => sprintf($lang['Adr_items_sell_confirm_price'], intval($price) , get_reward_name() ),
 563                  'L_YES' => $lang['Yes'],
 564                  'L_NO' => $lang['No'],
 565                  'S_SELL_CONFIRM_ACTION' => append_sid("adr_character_inventory.$phpEx"),
 566                  'HIDDEN_FIELDS' => $s_hidden_fields, 
 567              ));
 568  
 569  
 570          break;
 571  
 572          case 'sell_item' :
 573  
 574              $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . " 
 575                  WHERE item_owner_id = $user_id
 576                  AND item_in_shop = 0
 577                  AND item_duration > 0
 578                  AND item_auth = 0 
 579                  AND item_monster_thief = 0 ";
 580              if( !($result = $db->sql_query($sql)) )
 581              {
 582                  message_die(GENERAL_ERROR, $lang['Adr_shop_items_failure_deleted']);
 583              }
 584              $items = $db->sql_fetchrowset($result);
 585  
 586              while( list(,$item) = @each($items) )
 587              {
 588                  if ( isset($HTTP_POST_VARS[$item['item_id']]))
 589                  {
 590                      $item_id = $item['item_id'];
 591                      adr_sell_item($item_id , $user_id);
 592                  }
 593              }
 594  
 595              adr_previous( Adr_inventory_items_successful_selled , adr_character_inventory , '' );
 596  
 597          break;
 598  
 599          case 'warehouse' :
 600  
 601              $sql = "SELECT character_warehouse FROM " . ADR_CHARACTERS_TABLE . "
 602                  WHERE character_id = $user_id ";
 603              $result = $db->sql_query($sql);
 604              if( !$result )
 605              {
 606                  message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
 607              }
 608              $row = $db->sql_fetchrow($result);
 609              if ( $row['character_warehouse'] != 1 )
 610              {
 611                  adr_previous( Adr_lack_warehouse , adr_character_inventory , '' );    
 612              }
 613  
 614              // Define some values

 615              $items = ( isset($HTTP_POST_VARS['item_box']) ) ?  $HTTP_POST_VARS['item_box'] : array();
 616  
 617              $item_id_list .= '(';
 618              if ( count($items) > 0 )
 619              {    
 620                  for($i = 0; $i < count($items); $i++)
 621                  {
 622                         $item_id_list .= $items[$i].',';
 623                  }
 624              }
 625              $item_id_list .= '0)';
 626  
 627              $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "
 628                  WHERE item_owner_id = $user_id
 629                  AND item_in_shop = 0
 630                  AND item_duration > 0 
 631                  AND item_auth = 0 
 632                  AND item_monster_thief = 0 
 633                  AND item_id IN $item_id_list 
 634                  ORDER BY item_name ";
 635              if( !($result = $db->sql_query($sql)) )
 636              {
 637                  message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
 638              }
 639              $items = $db->sql_fetchrowset($result);
 640  
 641              $items_name = '';
 642              while( list(,$item) = @each($items) )
 643              {
 644                  $item_id = $item['item_id'];
 645  
 646                  $sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE ."
 647                      SET item_in_warehouse = 1
 648                      WHERE item_id = $item_id 
 649                      AND item_owner_id = $user_id ";
 650                  $result = $db->sql_query($sql);
 651                  if( !$result )
 652                  {
 653                      adr_previous( Adr_shop_items_failure_deleted , adr_character_inventory , '');
 654                  }
 655              }
 656  
 657              adr_previous( Adr_warehouse_items_successful_added , adr_character_inventory , '' );
 658  
 659  
 660          break;
 661  
 662          case 'shop' :
 663  
 664              $sql = "SELECT shop_id FROM " . ADR_SHOPS_TABLE . "
 665                  WHERE shop_owner_id = $user_id ";
 666              $result = $db->sql_query($sql);
 667              if( !$result )
 668              {
 669                  message_die(GENERAL_ERROR, 'Could not obtain shops information', "", __LINE__, __FILE__, $sql);
 670              }
 671              $row = $db->sql_fetchrow($result);
 672              if ( !(is_numeric($row['shop_id'])) )
 673              {
 674                  adr_previous( Adr_lack_shops , adr_character_inventory , '' );    
 675              }
 676  
 677              // Define some values

 678              $items = ( isset($HTTP_POST_VARS['item_box']) ) ?  $HTTP_POST_VARS['item_box'] : array();
 679  
 680              // Deny access if the user is in a battle

 681              $sql = "SELECT battle_id FROM  " . ADR_BATTLE_LIST_TABLE . "
 682                  WHERE battle_challenger_id = '$user_id'
 683                  AND battle_result = '0'
 684                  AND battle_type = '1'";
 685              if(!($result = $db->sql_query($sql))){
 686                  message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);}
 687              $bat = $db->sql_fetchrow($result);
 688              if(is_numeric($bat['battle_id']))
 689                  adr_previous(Adr_battle_no_move_to_shop, adr_character_inventory, '');
 690  
 691              $item_id_list .= '(';
 692              if ( count($items) > 0 )
 693              {    
 694                  for($i = 0; $i < count($items); $i++)
 695                  {
 696                         $item_id_list .= $items[$i].',';
 697                  }
 698              }
 699              $item_id_list .= '0)';
 700  
 701              $sql = "SELECT i.* FROM " . ADR_SHOPS_ITEMS_TABLE . " i
 702                  WHERE i.item_owner_id = $user_id
 703                  AND i.item_in_shop = 0
 704                  AND i.item_duration > 0 
 705                  AND i.item_auth = 0 
 706                  AND i.item_id IN $item_id_list 
 707                  ORDER BY i.item_name ";
 708              if( !($result = $db->sql_query($sql)) )
 709              {
 710                  message_die(GENERAL_ERROR, 'Could not obtain items information', "", __LINE__, __FILE__, $sql);
 711              }
 712              $items = $db->sql_fetchrowset($result);
 713  
 714              $items_name = '';
 715              while( list(,$item) = @each($items) )
 716              {
 717                  $item_id = $item['item_id'];
 718  
 719                  $sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE ."
 720                      SET item_in_shop = 1
 721                      WHERE item_id = $item_id 
 722                      AND item_owner_id = $user_id ";
 723                  $result = $db->sql_query($sql);
 724                  if( !$result )
 725                  {
 726                      adr_previous( Adr_shop_items_failure_deleted , adr_character_inventory , '');
 727                  }
 728              }
 729  
 730              // Set 'last updated' timestamp for user store

 731              $sql = "UPDATE " . ADR_SHOPS_TABLE ."
 732                  SET shop_last_updated = ".time()."
 733                  WHERE shop_owner_id = '$user_id'";
 734              $result = $db->sql_query($sql);
 735              if(!($result = $db->sql_query($sql))){
 736                  message_die(GENERAL_ERROR, 'Could not update last updated timestamp to personal store', "", __LINE__, __FILE__, $sql);}
 737  
 738              adr_previous( Adr_inventory_items_successful_added , adr_character_inventory , '' );
 739  
 740          break;
 741      }
 742  }
 743  
 744  else
 745  {
 746      adr_template_file('adr_inventory_body.tpl');
 747      $template->assign_block_vars('main',array());
 748  
 749      $sql = "SELECT i.* , q.item_quality_lang , t.item_type_lang FROM " . ADR_SHOPS_ITEMS_TABLE . " i
 750              LEFT JOIN " . ADR_SHOPS_ITEMS_QUALITY_TABLE . " q ON ( i.item_quality = q.item_quality_id )
 751              LEFT JOIN " . ADR_SHOPS_ITEMS_TYPE_TABLE . " t ON ( i.item_type_use = t.item_type_id )
 752          WHERE i.item_owner_id = $searchid
 753          AND i.item_in_shop = 0
 754          AND i.item_duration > 0
 755          AND i.item_in_warehouse < 1
 756          AND i.item_auth = 0 
 757          AND i.item_monster_thief = 0 
 758          $cat_sql
 759          ORDER BY $order_by";
 760      if( !($result = $db->sql_query($sql)) )
 761      {
 762          message_die(GENERAL_ERROR, 'Could not query users items', '', __LINE__, __FILE__, $sql);
 763      }
 764  
 765      if ( $row = $db->sql_fetchrow($result) )
 766      {
 767          $i = 0;
 768          do
 769          {
 770              $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
 771  
 772              $template->assign_block_vars('main.items', array(
 773                  "ROW_CLASS" => $row_class,
 774                  "ITEM_NAME" => adr_get_lang($row['item_name']),
 775                  "ITEM_DESC" => adr_get_lang($row['item_desc']),
 776                  "ITEM_IMG" => $row['item_icon'],
 777                  "ITEM_QUALITY" => $lang[$row['item_quality_lang']],
 778                  "ITEM_TYPE" => $lang[$row['item_type_lang']],
 779                  "ITEM_DURATION" => $row['item_duration'],
 780                  "ITEM_DURATION_MAX" => $row['item_duration_max'],
 781                  "ITEM_POWER" => $row['item_power'],
 782                  "ITEM_WEIGHT" => $row['item_weight'],
 783                  "ITEM_PRICE" => $row['item_price'],
 784                  "ITEM_ID" => $row['item_id'],
 785                  "U_ITEM_GIVE" => append_sid("adr_character_inventory.$phpEx?mode=give&amp;item_id=".$row['item_id']),
 786                  "U_ITEM_SELL" => append_sid("adr_character_inventory.$phpEx?mode=sell&amp;item_id=".$row['item_id']),
 787                  "U_ITEM_EDIT" => append_sid("adr_character_inventory.$phpEx?mode=edit&amp;item_id=".$row['item_id']),
 788                  "U_ITEM_SHOP" => append_sid("adr_character_inventory.$phpEx?mode=shop&amp;item_id=".$row['item_id']),
 789                  "U_ITEM_INFO" => append_sid("adr_character_inventory.$phpEx?mode=view_item&amp;item_owner_id=".$row['item_owner_id']."&amp;item_id=".$row['item_id'].""),
 790              ));
 791  
 792              if ( $user_id == $searchid )
 793              {
 794                  $template->assign_block_vars("main.items.owner", array());
 795              }
 796  
 797              $i++;
 798          }
 799          while ( $row = $db->sql_fetchrow($result) );
 800  
 801      }
 802  
 803      if ( $user_id == $searchid )
 804      {
 805          $colspan = 9;
 806          $template->assign_block_vars("main.owner", array());
 807  
 808          // Delete broken items from users inventory

 809          $sql = " DELETE FROM " . ADR_SHOPS_ITEMS_TABLE . "
 810              WHERE item_duration < 1 
 811              AND item_owner_id = $user_id ";
 812          if( !($result = $db->sql_query($sql)) )
 813          {
 814              message_die(GENERAL_ERROR, 'Could not delete broken items', '', __LINE__, __FILE__, $sql);
 815          }
 816      }
 817  
 818      $cat_sql = ( $cat ) ? 'AND item_type_use = '.$cat : '';
 819      $sql = "SELECT count(*) AS total FROM " . ADR_SHOPS_ITEMS_TABLE ." 
 820          WHERE item_owner_id = $searchid
 821          AND item_in_shop = 0
 822          AND item_duration > 0
 823          AND item_in_warehouse < 1
 824          AND item_monster_thief = 0  
 825          AND item_auth = 0 
 826          $cat_sql ";
 827      if ( !($result = $db->sql_query($sql)) )
 828      {
 829          message_die(GENERAL_ERROR, 'Error getting total users', '', __LINE__, __FILE__, $sql);
 830      }
 831      if ( $total = $db->sql_fetchrow($result) )
 832      {
 833          $total_items = $total['total'];
 834          $pagination = generate_pagination("adr_character_inventory.$phpEx?".POST_USERS_URL."=$searchid&amp;mode2=$mode2&amp;order=$sort_order&amp;cat=$cat", $total_items, $board_config['topics_per_page'], $start). '&nbsp;';    
 835      }
 836  
 837      $action_select = '<select name="mode">';
 838      $action_select .= '<option value = "">' . $lang['Adr_items_select_action'] . '</option>';
 839      $action_select .= '<option value = "give">' . $lang['Adr_items_give'] . '</option>';
 840      $action_select .= '<option value = "sell">' . $lang['Adr_items_sell'] . '</option>';
 841      $action_select .= '<option value = "edit">' . $lang['Adr_items_edit'] . '</option>';
 842      $action_select .= '<option value = "delete">' . $lang['Dispose'] . '</option>';
 843      $action_select .= '<option value = "warehouse">' . $lang['Adr_items_into_warehouse'] . '</option>';
 844      $action_select .= '<option value = "shop">' . $lang['Adr_items_into_shop'] . '</option>';
 845      $action_select .= '</select>';
 846  
 847      // Check if power limit is enabled

 848      if ( $adr_general['item_power_level'] == 1 )
 849      {
 850          $lang_power = $lang['Adr_items_level'];
 851      }
 852      else
 853      {
 854          $lang_power = $lang['Adr_items_power'];
 855      }
 856  
 857      $template->assign_vars(array(
 858          "COLSPAN" => $colspan,
 859          "ACTION_LIST" => $action_select,
 860          'SELECT_CAT' => $select_category,
 861          'PAGINATION' => $pagination,
 862          'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_items / $board_config['topics_per_page'] )), 
 863          "L_ITEM_NAME" => $lang['Adr_shops_categories_item_name'],
 864          "L_ITEM_DESC" => $lang['Adr_shops_categories_item_desc'],
 865          "L_ITEM_QUALITY" => $lang['Adr_items_quality'],
 866          "L_ITEM_POWER" => $lang_power,
 867          "L_ITEM_WEIGHT" => $lang['Adr_character_weight'],
 868          "L_ITEM_DURATION" => $lang['Adr_items_duration'],
 869          "L_ACTION" => $lang['Adr_items_action'],
 870          "L_SELECT_CAT" => $lang['Adr_items_select'],
 871          "L_ITEM_IMG" => $lang['Adr_races_image'],
 872          "L_ITEM_PRICE" => $lang['Adr_items_price'],
 873          "L_ITEM_TYPE" => $lang['Adr_items_type_use'],
 874          'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
 875          'L_ORDER' => $lang['Order'],
 876          'L_SORT' => $lang['Sort'],
 877          'L_GOTO_PAGE' => $lang['Goto_page'],
 878          'L_SUBMIT' => $lang['Submit'],
 879          'L_CHECK_ALL' => $lang['Adr_check_all'],
 880          'L_UNCHECK_ALL' => $lang['Adr_uncheck_all'],
 881          'S_MODE_SELECT' => $select_sort_mode,
 882          'S_ORDER_SELECT' => $select_sort_order,
 883          "S_ITEMS_ACTION" => append_sid("adr_character_inventory.$phpEx?".POST_USERS_URL."=$searchid&amp;mode2=$mode2&amp;order=$sort_order&amp;cat=$cat"),
 884          "S_HIDDEN_FIELDS" => $s_hidden_fields, 
 885      ));
 886  }
 887  
 888  include($phpbb_root_path . 'adr/includes/adr_header.'.$phpEx);
 889  
 890  $template->pparse('body');
 891  include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
 892   
 893  ?> 


[ Powered by PHPXref - Served by Debian GNU/Linux ]