Beispiel #1
0
 function SaveRegPlayer()
 {
     $post = JRequest::get('post');
     $row = new JTablePlayer($this->db);
     $row->registered = 1;
     $user = JFactory::getUser();
     $istlogo = JRequest::getVar('istlogo', 0, 'post', 'int');
     $post['def_img'] = JRequest::getVar('ph_default', 0, 'post', 'int');
     if ($user->get('guest')) {
         JError::raiseError(403, JText::_('Access Forbidden'));
         return;
     }
     $row->usr_id = $user->id;
     if (!$row->bind($post)) {
         JError::raiseError(500, $row->getError());
     }
     if (!$row->check()) {
         JError::raiseError(500, $row->getError());
     }
     // if new item order last in appropriate group
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
     }
     $row->checkin();
     $curid = $row->id;
     $this->usrnew = $curid;
     if (!$istlogo && !$row->id) {
         $query = "DELETE FROM #__bl_assign_photos WHERE cat_type='1' AND cat_id=" . $curid;
         $this->db->setQuery($query);
         $this->db->query();
         $error = $this->db->getErrorMsg();
         if ($error) {
             return JError::raiseError(500, $error);
         }
     }
     $query = "DELETE FROM #__bl_assign_photos WHERE cat_type = 1 AND cat_id = " . $row->id;
     $this->db->setQuery($query);
     $this->db->query();
     $error = $this->db->getErrorMsg();
     if ($error) {
         return JError::raiseError(500, $error);
     }
     if (isset($_POST['photos_id']) && count($_POST['photos_id'])) {
         for ($i = 0; $i < count($_POST['photos_id']); $i++) {
             $photo_id = intval($_POST['photos_id'][$i]);
             $photo_name = addslashes(strval($_POST['ph_names'][$i]));
             $query = "INSERT IGNORE INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $photo_id . "," . $row->id . ",1)";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
             $query = "UPDATE #__bl_photos SET ph_name = '" . $photo_name . "' WHERE id = " . $photo_id;
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         }
     }
     if (isset($_FILES['player_photo_1']['name']) && $_FILES['player_photo_1']['tmp_name'] != '' && isset($_FILES['player_photo_1']['tmp_name'])) {
         $bl_filename = strtolower($_FILES['player_photo_1']['name']);
         $ext = pathinfo($_FILES['player_photo_1']['name']);
         $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
         $bl_filename = str_replace(" ", "", $bl_filename);
         //echo $bl_filename;
         if ($this->uploadFile($_FILES['player_photo_1']['tmp_name'], $bl_filename)) {
             $post1['ph_filename'] = $bl_filename;
             $img1 = new JTablePhotos($this->db);
             $img1->id = 0;
             if (!$img1->bind($post1)) {
                 JError::raiseError(500, $img1->getError());
             }
             if (!$img1->check()) {
                 JError::raiseError(500, $img1->getError());
             }
             // if new item order last in appropriate group
             if (!$img1->store()) {
                 JError::raiseError(500, $img1->getError());
             }
             $img1->checkin();
             $query = "INSERT IGNORE INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $img1->id . "," . $row->id . ",1)";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         }
     } else {
         if ($_FILES['player_photo_1']['error'] == 1) {
             $this->mainframe->redirect('index.php?option=com_joomsport&task=regplayer&cid[]=' . $row->id, JText::_('BLBA_WRNGPHOTO'), 'warning');
         }
     }
     /*if(isset($img1)){
     			$query = "INSERT IGNORE INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(".$img1->id.",".$row->id.",1)";
     		 	$this->db->setQuery($query);
     			$this->db->query();
     			$error = $this->db->getErrorMsg();
     			if ($error)
     			{
     				return JError::raiseError(500, $error);
     			}
     		}*/
     //-------extra fields-----------//
     if (isset($_POST['extraf']) && count($_POST['extraf'])) {
         foreach ($_POST['extraf'] as $p => $dummy) {
             if (intval($_POST['extra_id'][$p])) {
                 $query = "SELECT season_related FROM `#__bl_extra_filds` WHERE id='" . intval($_POST['extra_id'][$p]) . "'";
                 $this->db->setQuery($query);
                 $season_related = $this->db->loadResult();
                 $db_season = $season_related ? $this->sid : 0;
                 $query = "DELETE FROM #__bl_extra_values WHERE f_id = " . intval($_POST['extra_id'][$p]) . " AND uid = " . $row->id . " AND season_id='" . $db_season . "'";
                 $this->db->setQuery($query);
                 $this->db->query();
                 if ($_POST['extra_ftype'][$p] == '2') {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue_text,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "',{$db_season})";
                 } else {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . $_POST['extraf'][$p] . "',{$db_season})";
                 }
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     }
 }
 public function savePlayer()
 {
     $mainframe = JFactory::getApplication();
     $post = JRequest::get('post');
     $post['about'] = JRequest::getVar('about', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['def_img'] = JRequest::getVar('ph_default', 0, 'post', 'int');
     $seasf_id = JRequest::getVar('seasf_id', 0, 'post', 'int');
     $usr_admins = JRequest::getVar('in_teams', array(0), '', 'array');
     JArrayHelper::toInteger($usr_admins, array(0));
     $row = new JTablePlayer($this->db);
     if (!$row->bind($post)) {
         JError::raiseError(500, $row->getError());
     }
     if (!$row->check()) {
         JError::raiseError(500, $row->getError());
     }
     // if new item order last in appropriate group
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
     }
     $row->checkin();
     $query = "SELECT p.id FROM #__bl_assign_photos as ph, #__bl_photos as p WHERE p.id = ph.photo_id AND ph.cat_type = 1 AND ph.cat_id = " . $row->id;
     $this->db->setQuery($query);
     $in_id = $this->db->loadColumn();
     $query = "DELETE FROM #__bl_assign_photos WHERE cat_type = 1 AND cat_id = " . $row->id;
     $this->db->setQuery($query);
     $this->db->query();
     if (isset($_POST['photos_id']) && count($_POST['photos_id'])) {
         for ($i = 0; $i < count($_POST['photos_id']); $i++) {
             $photo_id = intval($_POST['photos_id'][$i]);
             $photo_name = addslashes(strval($_POST['ph_names'][$i]));
             $query = "INSERT INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $photo_id . "," . $row->id . ",1)";
             $this->db->setQuery($query);
             $this->db->query();
             $query = "UPDATE #__bl_photos SET ph_name = '" . $photo_name . "' WHERE id = " . $photo_id;
             $this->db->setQuery($query);
             $this->db->query();
             $key = array_search($_POST['photos_id'][$i], $in_id);
             //print_r($key);die;
             if (is_int($key)) {
                 unset($in_id[$key]);
             }
         }
     }
     if (count($in_id)) {
         $query = "DELETE FROM #__bl_photos WHERE id IN(" . implode(',', $in_id) . ")";
         $this->db->setQuery($query);
         $this->db->query();
     }
     if ($_FILES['player_photo_1']['size']) {
         if (isset($_FILES['player_photo_1']['name']) && $_FILES['player_photo_1']['tmp_name'] != '' && isset($_FILES['player_photo_1']['tmp_name'])) {
             $bl_filename = strtolower($_FILES['player_photo_1']['name']);
             $ext = pathinfo($_FILES['player_photo_1']['name']);
             $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
             $bl_filename = str_replace(" ", "", $bl_filename);
             //echo $bl_filename;
             if ($this->uploadFile($_FILES['player_photo_1']['tmp_name'], $bl_filename)) {
                 $post1['ph_filename'] = $bl_filename;
                 $img1 = new JTablePhotos($this->db);
                 $img1->id = 0;
                 if (!$img1->bind($post1)) {
                     JError::raiseError(500, $img1->getError());
                 }
                 if (!$img1->check()) {
                     JError::raiseError(500, $img1->getError());
                 }
                 // if new item order last in appropriate group
                 if (!$img1->store()) {
                     JError::raiseError(500, $img1->getError());
                 }
                 $img1->checkin();
                 $query = "INSERT INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $img1->id . "," . $row->id . ",1)";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     } else {
         if ($_FILES['player_photo_1']['error'] == 1) {
             $mainframe->redirect('index.php?option=com_joomsport&task=player_edit&cid[]=' . $row->id, JText::_('BLBE_WRNGPHOTO'), 'warning');
         }
     }
     if ($_FILES['player_photo_2']['size']) {
         if (isset($_FILES['player_photo_2']['name']) && $_FILES['player_photo_2']['tmp_name'] != '' && isset($_FILES['player_photo_2']['tmp_name'])) {
             $bl_filename = strtolower($_FILES['player_photo_2']['name']);
             $ext = pathinfo($_FILES['player_photo_2']['name']);
             $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
             $bl_filename = str_replace(" ", "", $bl_filename);
             if ($this->uploadFile($_FILES['player_photo_2']['tmp_name'], $bl_filename)) {
                 $post2['ph_filename'] = $bl_filename;
                 $img2 = new JTablePhotos($this->db);
                 $img2->id = 0;
                 if (!$img2->bind($post2)) {
                     JError::raiseError(500, $img2->getError());
                 }
                 if (!$img2->check()) {
                     JError::raiseError(500, $img2->getError());
                 }
                 // if new item order last in appropriate group
                 if (!$img2->store()) {
                     JError::raiseError(500, $img2->getError());
                 }
                 $img2->checkin();
                 $query = "INSERT INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $img2->id . "," . $row->id . ",1)";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     } else {
         if ($_FILES['player_photo_2']['error'] == 1) {
             $mainframe->redirect('index.php?option=com_joomsport&task=player_edit&cid[]=' . $row->id, JText::_('BLBE_WRNGPHOTO'), 'warning');
         }
     }
     //-------extra fields-----------//
     if (isset($_POST['extraf']) && count($_POST['extraf'])) {
         foreach ($_POST['extraf'] as $p => $dummy) {
             if (intval($_POST['extra_id'][$p])) {
                 $query = "SELECT season_related FROM `#__bl_extra_filds` WHERE id='" . intval($_POST['extra_id'][$p]) . "'";
                 $this->db->setQuery($query);
                 $season_related = $this->db->loadResult();
                 $db_season = $season_related ? $seasf_id : 0;
                 $query = "DELETE FROM #__bl_extra_values WHERE f_id = " . intval($_POST['extra_id'][$p]) . " AND uid = " . $row->id . " AND season_id='" . $db_season . "'";
                 $this->db->setQuery($query);
                 $this->db->query();
                 if ($_POST['extra_ftype'][$p] == '2') {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue_text,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "',{$db_season})";
                 } else {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "',{$db_season})";
                 }
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     }
     //-------Bonuses points----//
     if (isset($_POST['sids']) && count($_POST['sids'])) {
         for ($p = 0; $p < count($_POST['sids']); $p++) {
             $query = "UPDATE #__bl_season_players SET bonus_point = " . intval($_POST['bonuses'][$p]) . " WHERE season_id=" . $_POST['sids'][$p] . " AND player_id=" . $row->id;
             $this->db->setQuery($query);
             $this->db->query();
         }
     }
     if ($seasf_id) {
         $query = "DELETE FROM #__bl_players_team WHERE confirmed='0' AND player_id = " . $row->id . " AND season_id=" . $seasf_id;
         $this->db->setQuery($query);
         $this->db->query();
         if (count($usr_admins)) {
             foreach ($usr_admins as $usrz) {
                 $query = "INSERT INTO #__bl_players_team(team_id,player_id,season_id) VALUES(" . $usrz . "," . $row->id . "," . $seasf_id . ")";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     }
     $this->_id = $row->id;
 }
 function savAdmPlayer()
 {
     $post = JRequest::get('post');
     $post['about'] = JRequest::getVar('about', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['def_img'] = JRequest::getVar('ph_default', 0, 'post', 'int');
     $s_id = JRequest::getVar('sid', 0, '', 'int');
     $tid = JRequest::getVar('tid', 0, '', 'int');
     $row = new JTablePlayer($this->db);
     $user = JFactory::getUser();
     $row->created_by = $user->id;
     if ($this->acl == 2) {
         $canmore = $post['id'] ? true : false;
         $query = "SELECT COUNT(*) FROM #__bl_players WHERE created_by=" . $user->id;
         $this->db->setQuery($query);
         $curcap = $this->db->loadResult();
         $teams_per_account = $this->getJS_Config('players_per_account');
         if ($curcap < $teams_per_account) {
             $canmore = true;
         }
         if (!$canmore) {
             JError::raiseError(403, JText::_('Access Forbidden'));
             return;
         }
     }
     if (!$row->bind($post)) {
         JError::raiseError(500, $row->getError());
     }
     if ($this->acl == 1 && $row->id && $this->_lists["jssa_editplayer"]) {
         JError::raiseError(500, $row->getError());
     }
     if (!$row->check()) {
         JError::raiseError(500, $row->getError());
     }
     // if new item order last in appropriate group
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
     }
     if ($this->acl == 1) {
         $topt = $this->getTournOpt($s_id);
         if ($topt->t_single) {
             $query = "INSERT IGNORE INTO #__bl_season_players(season_id,player_id) VALUES(" . $s_id . "," . $row->id . ")";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         } elseif (!$post["id"] && intval($post["teams_seas"])) {
             $query = "INSERT IGNORE INTO #__bl_players_team(team_id,player_id,season_id) VALUES(" . intval($post["teams_seas"]) . "," . $row->id . "," . $s_id . ")";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         }
     }
     $row->checkin();
     $query = "DELETE FROM #__bl_assign_photos WHERE cat_type = 1 AND cat_id = " . $row->id;
     $this->db->setQuery($query);
     $this->db->query();
     $error = $this->db->getErrorMsg();
     if ($error) {
         return JError::raiseError(500, $error);
     }
     if (isset($_POST['photos_id']) && count($_POST['photos_id'])) {
         for ($i = 0; $i < count($_POST['photos_id']); $i++) {
             $photo_id = intval($_POST['photos_id'][$i]);
             $photo_name = addslashes(strval($_POST['ph_names'][$i]));
             $query = "INSERT INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $photo_id . "," . $row->id . ",1)";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
             $query = "UPDATE #__bl_photos SET ph_name = '" . $photo_name . "' WHERE id = " . $photo_id;
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         }
     }
     if (isset($_FILES['player_photo_1']['name']) && $_FILES['player_photo_1']['tmp_name'] != '' && isset($_FILES['player_photo_1']['tmp_name'])) {
         $bl_filename = strtolower($_FILES['player_photo_1']['name']);
         $ext = pathinfo($_FILES['player_photo_1']['name']);
         $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
         $bl_filename = str_replace(" ", "", $bl_filename);
         //echo $bl_filename;
         if ($this->uploadFile($_FILES['player_photo_1']['tmp_name'], $bl_filename)) {
             $post1['ph_filename'] = $bl_filename;
             $img1 = new JTablePhotos($this->db);
             $img1->id = 0;
             if (!$img1->bind($post1)) {
                 JError::raiseError(500, $img1->getError());
             }
             if (!$img1->check()) {
                 JError::raiseError(500, $img1->getError());
             }
             // if new item order last in appropriate group
             if (!$img1->store()) {
                 JError::raiseError(500, $img1->getError());
             }
             $img1->checkin();
             $query = "INSERT INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $img1->id . "," . $row->id . ",1)";
             $this->db->setQuery($query);
             $this->db->query();
         }
     } else {
         if ($_FILES['player_photo_1']['error'] == 1) {
             //$this->mainframe->redirect( 'index.php?option=com_joomsport&task=adplayer_edit&controller=moder&tid='.$tid.'&cid[]='.$row->id,JText::_( 'BLBE_WRNGPHOTO' ),'warning');
             if ($this->acl == 1) {
                 $this->mainframe->redirect('index.php?option=com_joomsport&task=adplayer_edit&controller=admin&sid=' . $this->season_id . '&cid[]=' . $row->id, JText::_('BLBA_WRNGPHOTO'), 'warning');
             } else {
                 if ($this->acl == 2) {
                     $this->mainframe->redirect('index.php?option=com_joomsport&task=adplayer_edit&controller=moder&tid=' . $tid . '&cid[]=' . $row->id, JText::_('BLBA_WRNGPHOTO'), 'warning');
                 }
             }
         }
     }
     if (isset($_FILES['player_photo_2']['name']) && $_FILES['player_photo_2']['tmp_name'] != '' && isset($_FILES['player_photo_2']['tmp_name'])) {
         $bl_filename = strtolower($_FILES['player_photo_2']['name']);
         $ext = pathinfo($_FILES['player_photo_2']['name']);
         $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
         $bl_filename = str_replace(" ", "", $bl_filename);
         if ($this->uploadFile($_FILES['player_photo_2']['tmp_name'], $bl_filename)) {
             $post2['ph_filename'] = $bl_filename;
             $img2 = new JTablePhotos($this->db);
             $img2->id = 0;
             if (!$img2->bind($post2)) {
                 JError::raiseError(500, $img2->getError());
             }
             if (!$img2->check()) {
                 JError::raiseError(500, $img2->getError());
             }
             // if new item order last in appropriate group
             if (!$img2->store()) {
                 JError::raiseError(500, $img2->getError());
             }
             $img2->checkin();
             $query = "INSERT INTO #__bl_assign_photos(photo_id,cat_id,cat_type) VALUES(" . $img2->id . "," . $row->id . ",1)";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         }
     } else {
         if ($_FILES['player_photo_2']['error'] == 1) {
             if ($this->acl == 1) {
                 $this->mainframe->redirect('index.php?option=com_joomsport&task=adplayer_edit&controller=admin&sid=' . $this->season_id . '&cid[]=' . $row->id, JText::_('BLBA_WRNGPHOTO'), 'warning');
             } else {
                 if ($this->acl == 2) {
                     $this->mainframe->redirect('index.php?option=com_joomsport&task=adplayer_edit&controller=moder&tid=' . $tid . '&cid[]=' . $row->id, JText::_('BLBA_WRNGPHOTO'), 'warning');
                 }
             }
         }
     }
     if ($this->acl == 2) {
         $s_id = $this->mainframe->getUserStateFromRequest('com_joomsport.moderseason', 'moderseason', 0, 'int');
         $query = "SELECT CONCAT(tr.name,' ',s.s_name) as t_name,s.s_id as id FROM #__bl_season_teams as t,#__bl_seasons as s,#__bl_tournament as tr WHERE s.published=1 AND tr.id=s.t_id AND s.s_id=t.season_id AND t.team_id=" . $tid . " ORDER BY s.s_id desc";
         $this->db->setQuery($query);
         $seass = $this->db->loadObjectList();
         $error = $this->db->getErrorMsg();
         if ($error) {
             return JError::raiseError(500, $error);
         }
         if (!$s_id) {
             $s_id = $seass[0]->id;
         }
     }
     //-------extra fields-----------//
     if (isset($_POST['extraf']) && count($_POST['extraf'])) {
         foreach ($_POST['extraf'] as $p => $dummy) {
             if (intval($_POST['extra_id'][$p])) {
                 $query = "SELECT season_related FROM `#__bl_extra_filds` WHERE id='" . intval($_POST['extra_id'][$p]) . "'";
                 $this->db->setQuery($query);
                 $season_related = $this->db->loadResult();
                 $db_season = $season_related ? $s_id : 0;
                 $query = "DELETE FROM #__bl_extra_values WHERE f_id = " . intval($_POST['extra_id'][$p]) . " AND uid = " . $row->id . " AND season_id='" . $db_season . "'";
                 $this->db->setQuery($query);
                 $this->db->query();
                 if ($_POST['extra_ftype'][$p] == '2') {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue_text,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "',{$db_season})";
                 } else {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "',{$db_season})";
                 }
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     }
     $this->id = $row->id;
     $this->season_id = $s_id;
     $this->tid = $tid;
     $this->is_first = $post['id'] ? 1 : 0;
 }