Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.75 KB | None | 0 0
  1. <?php
  2.  /*
  3.  * Project:     EQdkp-Plus
  4.  * License:     Creative Commons - Attribution-Noncommercial-Share Alike 3.0 Unported
  5.  * Link:        http://creativecommons.org/licenses/by-nc-sa/3.0/
  6.  * -----------------------------------------------------------------------
  7.  * Began:       2011
  8.  * Date:        $Date: 2014-05-12 22:17:08 +0200 (Mo, 12. Mai 2014) $
  9.  * -----------------------------------------------------------------------
  10.  * @author      $Author: wallenium $
  11.  * @copyright   2006-2011 EQdkp-Plus Developer Team
  12.  * @link        http://eqdkp-plus.com
  13.  * @package     eqdkp-plus
  14.  * @version     $Rev: 14206 $
  15.  *
  16.  * $Id: charimporter.php 14206 2014-05-12 20:17:08Z wallenium $
  17.  */
  18.  
  19. define('EQDKP_INC', true);
  20. $eqdkp_root_path = './../../../';
  21. include_once ($eqdkp_root_path . 'common.php');
  22.  
  23. class charImporter extends page_generic {
  24.     public static function __shortcuts() {
  25.         $shortcuts = array('user', 'tpl', 'in', 'pdh', 'game', 'core', 'html', 'time', 'config');
  26.         return array_merge(parent::$shortcuts, $shortcuts);
  27.     }
  28.  
  29.     public function __construct() {
  30.         $handler = array(
  31.             'massupdate'        => array('process' => 'perform_massupdate'),
  32.             'resetcache'        => array('process' => 'perform_resetcache'),
  33.             'ajax_massupdate'   => array('process' => 'ajax_massupdate'),
  34.             'ajax_mudate'       => array('process' => 'ajax_massupdatedate'),
  35.         );
  36.         parent::__construct(false, $handler, array());
  37.         $this->user->check_auth('u_member_man');
  38.         $this->user->check_auth('u_member_add');
  39.         $this->game->new_object('bnet_armory', 'armory', array(unsanitize($this->config->get('uc_server_loc')), $this->config->get('uc_data_lang')));
  40.         $this->process();
  41.     }
  42.  
  43.     public function perform_resetcache(){
  44.         // delete the cache folder
  45.         $this->game->obj['armory']->DeleteCache();
  46.  
  47.         // Output the success message
  48.         $hmtlout = '<div id="guildimport_dataset">
  49.                         <div id="controlbox">
  50.                             <fieldset class="settings">
  51.                                 <dl>
  52.                                     '.$this->game->glang('uc_importcache_cleared').'
  53.                                 </dl>
  54.                             </fieldset>
  55.                         </div>
  56.                     </div>';
  57.  
  58.         $this->tpl->assign_vars(array(
  59.             'DATA'      => $hmtlout,
  60.             'STEP'      => ''
  61.         ));
  62.  
  63.         $this->core->set_vars(array(
  64.             'page_title'        => $this->user->lang('raidevent_raid_guests'),
  65.             'header_format'     => 'simple',
  66.             'template_file'     => 'importer.html',
  67.             'display'           => true
  68.         ));
  69.     }
  70.  
  71.     public function perform_massupdate(){
  72.         // check permission again, cause this is for admins only
  73.         $this->user->check_auth('a_members_man');
  74.  
  75.         // quit if there is not a server….
  76.         if($this->config->get('uc_servername') == ''){
  77.             return '<fieldset class="settings mediumsettings">
  78.                             <dl>
  79.                                 <dt><label>'.$this->game->glang('uc_error_head').'</label></dt>
  80.                                 <dd>'.$this->game->glang('uc_error_noserver').'</dd>
  81.                             </dl>
  82.                         </fieldset>';
  83.         }
  84.  
  85.         $memberArry = array();
  86.         $members    = $this->pdh->get('member', 'names', array());
  87.         if(is_array($members)){
  88.             asort($members);
  89.             foreach($members as $membernames){
  90.                 if($membernames != ''){
  91.                     $charid = $this->pdh->get('member', 'id', array($membernames));
  92.                     if($charid){
  93.                         $memberArry[] = array(
  94.                             'charname'  => $membernames,
  95.                             'charid'    => $charid,
  96.                         );
  97.                     }
  98.                 }
  99.             }
  100.         }
  101.         $hmtlout = '<div id="guildimport_dataset">
  102.                         <div id="controlbox">
  103.                             <fieldset class="settings">
  104.                                 <dl>
  105.                                     '.$this->game->glang('uc_massupd_loading').'
  106.                                     <div id="progressbar"></div>
  107.                                 </dl>
  108.                             </fieldset>
  109.                         </div>
  110.                         <fieldset class="settings data">
  111.                         </fieldset>
  112.                     </div>';
  113.  
  114.         $this->tpl->add_js('$( "#progressbar" ).progressbar({ value: 0 }); getData();', 'docready');
  115.         $this->tpl->add_js('
  116.             var chardataArry = $.parseJSON(\''.json_encode($memberArry).'\');
  117.             function getData(i){
  118.                 if (!i)
  119.                     i=0;
  120.    
  121.                 if (chardataArry.length >= i){
  122.                     $.post("charimporter.php?ajax_massupdate=true&totalcount="+chardataArry.length+"&actcount="+i, chardataArry[i], function(data){
  123.                         chardata = $.parseJSON(data);
  124.                         if(chardata.success == "imported"){
  125.                             successdata = "<span style=\"color:green;\">'.$this->game->glang('uc_armory_updated').'</span>";
  126.                         }else{
  127.                             successdata = "<span style=\"color:red;\">'.$this->game->glang('uc_armory_updfailed').'<br/>"+
  128.                             ((chardata.error) ? "'.$this->game->glang('uc_armory_impfail_reason').' "+chardata.error : "")+"</span>";
  129.                         }
  130.                         $("#guildimport_dataset fieldset.data").prepend("<dl><dt><label><img src=\""+ chardata.image +"\" alt=\"charicon\" height=\"84\" width=\"84\" /></label></dt><dd>"+ chardata.name+"<br/>"+ successdata +"</dd></dl>").children(":first").hide().fadeIn("slow");
  131.                         $("#progressbar").progressbar({ value: ((i/chardataArry.length)*100) })
  132.                         if(chardataArry.length > i+1){
  133.                             getData(i+1);
  134.                         }else{
  135.                             $.post("charimporter.php?ajax_mudate=true");
  136.                             $("#controlbox").html("<dl><div class=\"greenbox roundbox\"><div class=\"icon_ok\" id=\"error_message_txt\">'.$this->game->glang('uc_cupdt_header_fnsh').'</div></div></dl>").fadeIn("slow");
  137.                             return;
  138.                         }
  139.                     });
  140.                 }
  141.             }');
  142.  
  143.         $this->tpl->assign_vars(array(
  144.             'DATA'      => $hmtlout,
  145.             'STEP'      => ''
  146.         ));
  147.  
  148.         $this->core->set_vars(array(
  149.             'page_title'        => $this->user->lang('raidevent_raid_guests'),
  150.             'header_format'     => 'simple',
  151.             'template_file'     => 'importer.html',
  152.             'display'           => true
  153.         ));
  154.     }
  155.  
  156.     public function ajax_massupdatedate(){
  157.         $this->config->set(array('uc_profileimported'=> $this->time->time));
  158.     }
  159.  
  160.     public function ajax_massupdate(){
  161.         // due to connected/virtual realms, check for a servername of the char
  162.         $char_server    = $this->pdh->get('member', 'profile_field', array($this->in->get('charid', 0), 'servername'));
  163.         $servername     = ($char_server != '') ? $char_server : $this->config->get('uc_servername');
  164.         $chardata       = $this->game->obj['armory']->character(unsanitize($this->in->get('charname', '')), unsanitize($servername), true);
  165.  
  166.         if(!isset($chardata['status'])){
  167.             $errormsg   = '';
  168.             $charname   = $chardata['name'];
  169.             $charicon   = $this->game->obj['armory']->characterIcon($chardata);
  170.  
  171.             // insert into database
  172.             $info       = $this->pdh->put('member', 'addorupdate_member', array($this->in->get('charid', 0), array(
  173.                 'name'              => $this->in->get('charname', ''),
  174.                 'lvl'               => $chardata['level'],
  175.                 'gender'            => $this->game->obj['armory']->ConvertID($chardata['gender'], 'int', 'gender'),
  176.                 'raceid'            => $this->game->obj['armory']->ConvertID($chardata['race'], 'int', 'races'),
  177.                 'classid'           => $this->game->obj['armory']->ConvertID($chardata['class'], 'int', 'classes'),
  178.                 'guild'             => $chardata['guild']['name'],
  179.                 'last_update'       => ($chardata['lastModified']/1000),
  180.                 'prof1_name'        => $this->game->get_id('professions', $chardata['professions']['primary'][0]['name']),
  181.                 'prof1_value'       => $chardata['professions']['primary'][0]['rank'],
  182.                 'prof2_name'        => $this->game->get_id('professions', $chardata['professions']['primary'][1]['name']),
  183.                 'prof2_value'       => $chardata['professions']['primary'][1]['rank'],
  184.                 'skill_1'           => $this->game->obj['armory']->ConvertTalent($chardata['talents'][0]['spec']['icon']),
  185.                 'skill_2'           => $this->game->obj['armory']->ConvertTalent($chardata['talents'][1]['spec']['icon']),
  186.                 'health_bar'        => $chardata['stats']['health'],
  187.                 'second_bar'        => $chardata['stats']['power'],
  188.                 'second_name'       => $chardata['stats']['powerType'],
  189.             ), $this->in->get('overtakeuser', 0)));
  190.  
  191.             $this->pdh->process_hook_queue();
  192.             $successmsg = ($info) ? 'imported' : 'error';
  193.         }else{
  194.             $successmsg = 'error';
  195.             $errormsg   = $chardata['reason'];
  196.             $charname   = $this->in->get('charname', '');
  197.             $charicon   = $this->root_path.'images/no_pic.png';
  198.         }
  199.  
  200.         die(json_encode(array(
  201.             'image'     => $charicon,
  202.             'name'      => $charname,
  203.             'success'   => $successmsg,
  204.             'error'     => $errormsg
  205.         )));
  206.     }
  207.  
  208.     public function perform_step0(){
  209.  
  210.         $tmpmemname = '';
  211.         if($this->in->get('member_id', 0) > 0){
  212.             $tmpmemname = $this->pdh->get('member', 'name', array($this->in->get('member_id', 0)));
  213.         }
  214.  
  215.         // generate output
  216.         $hmtlout = '<fieldset class="settings mediumsettings">
  217.             <dl>
  218.                 <dt><label>'.$this->game->glang('uc_charname').'</label></dt>
  219.                 <dd>'.$this->html->widget(array('fieldtype'=>'text','name'=>'charname','value'=>(($tmpmemname) ? $tmpmemname : ''), 'size'=>'25')).'</dd>
  220.             </dl>';
  221.        
  222.         // Server Name
  223.         $hmtlout .= '<dl>
  224.                 <dt><label>'.$this->game->glang('uc_servername').'</label></dt>
  225.                 <dd>';
  226.         $hmtlout .= $this->html->widget(array('fieldtype'=>'autocomplete','name'=>'servername','selected'=>(($this->config->get('uc_servername')) ? stripslashes($this->config->get('uc_servername')) : ''), 'size'=>'25', 'edecode' => true, 'options' => $this->game->get('realmlist')));
  227.         $hmtlout .= '</dd>
  228.             </dl>
  229.             <dl>
  230.                 <dt><label>'.$this->game->glang('uc_server_loc').'</label></dt>
  231.                 <dd>';
  232.         if($this->config->get('uc_server_loc')){
  233.             $hmtlout .= $this->config->get('uc_server_loc');
  234.             $hmtlout .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'server_loc','value'=>$this->config->get('uc_server_loc')));
  235.         }else{
  236.             $hmtlout .= $this->html->DropDown('server_loc', $this->game->obj['armory']->getServerLoc(), '', '', '', 'input');
  237.         }
  238.         $hmtlout .= '</dd>
  239.             </dl>';
  240.        
  241.         $hmtlout .= '</fieldset>';
  242.         $hmtlout .= '<br/><input type="submit" name="submiti" value="'.$this->game->glang('uc_import_forw').'" class="mainoption" />';
  243.         return $hmtlout;
  244.     }
  245.  
  246.     public function perform_step1(){
  247.         $hmtlout = '';
  248.         if($this->in->get('member_id', 0) > 0){
  249.             // We'll update an existing one...
  250.             $isindatabase   = $this->in->get('member_id', 0);
  251.             $isMemberName   = $this->pdh->get('member', 'name', array($isindatabase));
  252.             $isServerName   = $this->config->get('uc_servername');
  253.             $isServerLoc    = $this->config->get('uc_server_loc');
  254.             $is_mine        = ($this->pdh->get('member', 'userid', array($isindatabase)) == $this->user->data['user_id']) ? true : false;
  255.         }else{
  256.             // Check for existing member name
  257.             $isindatabase   = $this->pdh->get('member', 'id', array($this->in->get('charname')));
  258.             $hasuserid      = ($isindatabase > 0) ? $this->pdh->get('member', 'userid', array($isindatabase)) : 0;
  259.             $isMemberName   = $this->in->get('charname');
  260.             $isServerName   = $this->in->get('servername');
  261.             $isServerLoc    = $this->in->get('server_loc');
  262.             if($this->user->check_auth('a_charmanager_config', false)){
  263.                 $is_mine    = true;         // We are an administrator, its always mine..
  264.             }else{
  265.                 $is_mine    = (($hasuserid > 0) ? (($hasuserid == $this->user->data['user_id']) ? true : false) : true);    // we are a normal user
  266.             }
  267.         }
  268.  
  269.         if($is_mine){
  270.             // Load the Armory Data
  271.             $this->game->obj['armory']->setSettings(array('loc'=>$isServerLoc));
  272.             $chardata   = $this->game->obj['armory']->character(unsanitize($isMemberName), unsanitize($isServerName), true);
  273.  
  274.             // Basics
  275.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'member_id','value'=>$isindatabase));
  276.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'member_name','value'=>$isMemberName));
  277.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'member_level','value'=>$chardata['level']));
  278.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'gender','value'=>$this->game->obj['armory']->ConvertID($chardata['gender'], 'int', 'gender')));
  279.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'member_race_id','value'=>$this->game->obj['armory']->ConvertID($chardata['race'], 'int', 'races')));
  280.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'member_class_id','value'=>$this->game->obj['armory']->ConvertID($chardata['class'], 'int', 'classes')));
  281.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'guild','value'=>$chardata['guild']['name']));
  282.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'servername','value'=>$isServerName));
  283.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'last_update','value'=>($chardata['lastModified']/1000)));
  284.  
  285.             // primary professions
  286.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'prof1_name','value'=>$chardata['professions']['primary'][0]['name']));
  287.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'prof1_value','value'=>$chardata['professions']['primary'][0]['rank']));
  288.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'prof2_name','value'=>$chardata['professions']['primary'][1]['name']));
  289.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'prof2_value','value'=>$chardata['professions']['primary'][1]['rank']));
  290.  
  291.             // talents
  292.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'skill_1','value'=>$this->game->obj['armory']->ConvertTalent($chardata['talents'][0]['spec']['icon'])));
  293.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'skill_2','value'=>$this->game->obj['armory']->ConvertTalent($chardata['talents'][1]['spec']['icon'])));
  294.  
  295.             // health/power bar
  296.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'health_bar','value'=>$chardata['stats']['health']));
  297.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'second_bar','value'=>$chardata['stats']['power']));
  298.             $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'second_name','value'=>$chardata['stats']['powerType']));
  299.  
  300.             // viewable Output
  301.             if(!isset($chardata['status'])){
  302.                 $hmtlout    .= '
  303.                 <div class="errorbox roundbox">
  304.                     <div class="icon_false">'.$this->game->glang('uc_charfound3').'</div>
  305.                 </div>
  306.  
  307.                 <fieldset class="settings mediumsettings">
  308.                     <dl>
  309.                         <dt><label><img src="'.$this->game->obj['armory']->characterIcon($chardata).'" name="char_icon" alt="icon" width="44px" height="44px" align="middle" /></label></dt>
  310.                         <dd>
  311.                             '.sprintf($this->game->glang('uc_charfound'), $isMemberName).'<br />
  312.                             '.sprintf($this->game->glang('uc_charfound2'), $this->time->user_date(($chardata['lastModified']/1000))).'
  313.                         </dd>
  314.                     </dl>
  315.                     <dl>';
  316.                 if(!$isindatabase){
  317.                     if($this->user->check_auth('u_member_conn', false)){
  318.                         $hmtlout    .= $this->html->widget(array('fieldtype'=>'checkbox','name'=>'overtakeuser','selected'=>'1')).' '.$this->user->lang('overtake_char');
  319.                     }else{
  320.                         $hmtlout    .= $this->html->widget(array('fieldtype'=>'checkbox','name'=>'overtakeuser','selected'=>'1', 'disabled'=>true));
  321.                         $hmtlout    .= $this->html->widget(array('fieldtype'=>'hidden','name'=>'overtakeuser','value'=>'1'));
  322.                     }
  323.                 }
  324.                 $hmtlout    .= '
  325.                     </dl>
  326.                     </fieldset>';
  327.                 $hmtlout        .= '<center><input type="submit" name="submiti" value="'.$this->game->glang('uc_prof_import').'" class="mainoption" /></center>';
  328.             }else{
  329.                 $hmtlout        .= '<div class="errorbox roundbox">
  330.                                         <div class="icon_false"><b>WARNING: </b> '.$chardata['reason'].'</div>
  331.                                     </div>';
  332.             }
  333.         }else{
  334.             $hmtlout    .= '<div class="errorbox roundbox">
  335.                                 <div class="icon_false">'.$this->game->glang('uc_notyourchar').'</div>
  336.                             </div>';
  337.         }
  338.         return $hmtlout;
  339.     }
  340.  
  341.     public function perform_step2(){
  342.         $data = array(
  343.             'name'              => $this->in->get('member_name'),
  344.             'lvl'               => $this->in->get('member_level', 0),
  345.             'gender'            => $this->in->get('gender', 'Male'),
  346.             'raceid'            => $this->in->get('member_race_id', 0),
  347.             'classid'           => $this->in->get('member_class_id', 0),
  348.             'guild'             => $this->in->get('guild',''),
  349.             'last_update'       => $this->in->get('last_update', 0),
  350.             'prof1_name'        => $this->game->get_id('professions', $this->in->get('prof1_name', '')),
  351.             'prof1_value'       => $this->in->get('prof1_value', 0),
  352.             'prof2_name'        => $this->game->get_id('professions', $this->in->get('prof2_name', '')),
  353.             'prof2_value'       => $this->in->get('prof2_value', 0),
  354.             'skill_1'           => $this->in->get('skill_1', 0),
  355.             'skill_2'           => $this->in->get('skill_2', 0),
  356.             'health_bar'        => $this->in->get('health_bar', 0),
  357.             'second_bar'        => $this->in->get('second_bar', 0),
  358.             'second_name'       => $this->in->get('second_name', ''),
  359.             'servername'        => $this->in->get('servername', ''),
  360.         );
  361.  
  362.         $info       = $this->pdh->put('member', 'addorupdate_member', array($this->in->get('member_id', 0), $data, $this->in->get('overtakeuser', 0)));
  363.         $this->pdh->process_hook_queue();
  364.         if($info){
  365.             $hmtlout    = '<div class="greenbox roundbox">
  366.                                 <div class="icon_ok">'.$this->game->glang('uc_armory_updated').'</div>
  367.                             </div>';
  368.         }else{
  369.             $hmtlout    = '<div class="errorbox roundbox">
  370.                                 <div class="icon_false">'.$this->game->glang('uc_armory_updfailed').'</div>
  371.                             </div>';
  372.         }
  373.         return $hmtlout;
  374.     }
  375.  
  376.     public function display(){
  377.  
  378.         // quit if there is not a server….
  379.         if($this->config->get('uc_servername') == ''){
  380.             $this->tpl->assign_vars(array(
  381.                 'DATA'      => '<fieldset class="settings mediumsettings">
  382.                             <dl>
  383.                                 <dt><label>'.$this->game->glang('uc_error_head').'</label></dt>
  384.                                 <dd>'.$this->game->glang('uc_error_noserver').'</dd>
  385.                             </dl>
  386.                         </fieldset>'
  387.             ));
  388.         }else{
  389.             $stepnumber     = ($this->config->get('uc_servername') && $this->config->get('uc_server_loc') && $this->in->get('member_id',0) > 0 && $this->in->get('step',0) == 0) ? 1 : $this->in->get('step',0);
  390.             $urladdition     = ($this->in->get('member_id',0)) ? '&amp;member_id='.$this->in->get('member_id',0) : '';
  391.             $funcname        = 'perform_step'.$stepnumber;
  392.             $this->tpl->assign_vars(array(
  393.                 'DATA'      => $this->$funcname(),
  394.                 'STEP'      => ($stepnumber+1).$urladdition
  395.             ));
  396.         }
  397.         $this->core->set_vars(array(
  398.             'page_title'        => $this->user->lang('raidevent_raid_guests'),
  399.             'header_format'     => 'simple',
  400.             'template_file'     => 'importer.html',
  401.             'display'           => true
  402.         ));
  403.     }
  404. }
  405. if(version_compare(PHP_VERSION, '5.3.0', '<')) registry::add_const('short_charImporter', charImporter::__shortcuts());
  406. registry::register('charImporter');
  407. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement