示例#1
0
 function SaveAdmTeam()
 {
     $post = JRequest::get('post');
     if ($this->acl == 1) {
         if (!$this->getJS_Config("jssa_editteam")) {
             JError::raiseError(500, '');
         }
         $s_id = JRequest::getVar('sid', 0, '', 'int');
     } else {
         $post['id'] = JRequest::getVar('tid', 0, 'post', 'int');
     }
     $msg = '';
     $post['t_descr'] = JRequest::getVar('t_descr', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['def_img'] = JRequest::getVar('ph_default', 0, 'post', 'int');
     $row = new JTableTeams($this->db);
     $error = $this->db->getErrorMsg();
     if ($error) {
         return JError::raiseError(500, $error);
     }
     $istlogo = JRequest::getVar('istlogo', 0, 'post', 'int');
     if (!$istlogo) {
         $post['t_emblem'] = '';
     }
     if (isset($_FILES['t_logo']['name']) && $_FILES['t_logo']['tmp_name'] != '' && isset($_FILES['t_logo']['tmp_name'])) {
         $bl_filename = strtolower($_FILES['t_logo']['name']);
         $ext = pathinfo($_FILES['t_logo']['name']);
         $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
         $bl_filename = str_replace(" ", "", $bl_filename);
         if ($this->uploadFile($_FILES['t_logo']['tmp_name'], $bl_filename)) {
             $post['t_emblem'] = $bl_filename;
         }
     }
     if (!$row->bind($post)) {
         JError::raiseError(500, $row->getError());
     }
     $pzt = 1;
     if (!$row->id) {
         if ($this->acl == 2) {
             return JError::raiseError(500, $error);
         } else {
             $pzt = 0;
         }
     }
     if (!$row->check()) {
         JError::raiseError(500, $row->getError());
     }
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
     }
     $row->checkin();
     if (!$pzt) {
         $query = "INSERT INTO #__bl_season_teams(season_id,team_id) VALUES(" . $s_id . "," . $row->id . ")";
         $this->db->setQuery($query);
         $this->db->query();
     }
     $query = "DELETE FROM #__bl_assign_photos WHERE cat_type = 2 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 . ",2)";
             $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);
         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 (!$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 . ",2)";
             $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) {
             if ($this->acl == 1) {
                 $this->mainframe->redirect('index.php?option=com_joomsport&task=team_edit&controller=admin&cid[]=' . $row->id . '&sid=' . $this->season_id, JText::_('BLBA_WRNGPHOTO'), 'warning');
             } else {
                 if ($this->acl == 2) {
                     $this->mainframe->redirect('index.php?option=com_joomsport&task=team_edit&controller=moder&tid=' . $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 (!$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 . ",2)";
             $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=team_edit&controller=admin&cid[]=' . $row->id . '&sid=' . $this->season_id, JText::_('BLBA_WRNGPHOTO'), 'warning');
             } else {
                 if ($this->acl == 2) {
                     $this->mainframe->redirect('index.php?option=com_joomsport&task=team_edit&controller=moder&tid=' . $row->id, JText::_('BLBA_WRNGPHOTO'), 'warning');
                 }
             }
         }
     }
     if ($this->acl == 2) {
         $seasf_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=" . $row->id . " 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 (!$seasf_id) {
             $seasf_id = $seass[0]->id;
         }
         $s_id = $seasf_id;
     }
     //-------extra fields-----------//
     if (isset($_POST['extraf']) && count($_POST['extraf'])) {
         foreach ($_POST['extraf'] as $p => $dummy) {
             $query = "SELECT season_related FROM #__bl_extra_filds WHERE id='" . intval($_POST['extra_id'][$p]) . "'";
             $this->db->setQuery($query);
             $seas_relat = $this->db->loadResult();
             $query = "DELETE FROM #__bl_extra_values WHERE f_id = " . $_POST['extra_id'][$p] . " AND uid = " . $row->id . " " . ($seas_relat ? " AND season_id=" . intval($s_id) : "");
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
             $fld = $_POST['extra_ftype'][$p] == 2 ? 'fvalue_text' : 'fvalue';
             $inserted_seas = $seas_relat ? $s_id : 0;
             $query = "INSERT INTO #__bl_extra_values(f_id,uid,`" . $fld . "`,season_id) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "'," . $inserted_seas . ")";
             $this->db->setQuery($query);
             $this->db->query();
             $error = $this->db->getErrorMsg();
             if ($error) {
                 return JError::raiseError(500, $error);
             }
         }
     }
     //-------Players----//
     if ($this->acl == 1) {
         if ($s_id && $row->id) {
             $query = "DELETE FROM #__bl_players_team WHERE team_id=" . $row->id . " AND season_id=" . $s_id;
             $this->db->setQuery($query);
             $this->db->query();
             if (isset($_POST['teampl']) && count($_POST['teampl'])) {
                 for ($p = 0; $p < count($_POST['teampl']); $p++) {
                     $query = "INSERT IGNORE INTO #__bl_players_team(team_id,player_id,season_id) VALUES(" . $row->id . "," . intval($_POST['teampl'][$p]) . "," . $s_id . ")";
                     $this->db->setQuery($query);
                     $this->db->query();
                 }
             }
         }
         $this->season_id = $s_id;
     } else {
         $inviteoradd = $this->getJS_Config('esport_invite_player');
         if ($seasf_id) {
             $plzold = array();
             if (isset($_POST['teampl']) && count($_POST['teampl'])) {
                 for ($p = 0; $p < count($_POST['teampl']); $p++) {
                     if (intval($_POST['teampl'][$p])) {
                         $query = "SELECT player_id FROM #__bl_players_team WHERE player_id = " . intval($_POST['teampl'][$p]) . " AND team_id = {$row->id} AND season_id = {$seasf_id}";
                         $this->db->setQuery($query);
                         $plzold[] = intval($_POST['teampl'][$p]);
                         if (!$this->db->loadResult()) {
                             $query = "INSERT IGNORE INTO #__bl_players_team(team_id,player_id,season_id,confirmed) VALUES(" . $row->id . "," . intval($_POST['teampl'][$p]) . "," . $seasf_id . "," . ($inviteoradd ? 1 : 0) . ")";
                             $this->db->setQuery($query);
                             $this->db->query();
                             $error = $this->db->getErrorMsg();
                             if ($error) {
                                 return JError::raiseError(500, $error);
                             }
                             //invite
                             if ($inviteoradd) {
                                 mt_srand((double) microtime());
                                 $gen = mt_rand() . "prI" . microtime();
                                 $gen = str_replace(" ", "", $gen);
                                 $this->InvitePlayer(intval($_POST['teampl'][$p]), $row->t_name, $seasf_id, $gen);
                                 $query = "UPDATE #__bl_players_team SET invitekey='" . $gen . "' WHERE team_id = " . $row->id . " AND player_id = " . intval($_POST['teampl'][$p]) . "  AND season_id = " . $seasf_id;
                                 $this->db->setQuery($query);
                                 $this->db->query();
                                 $error = $this->db->getErrorMsg();
                                 if ($error) {
                                     return JError::raiseError(500, $error);
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $query = "DELETE FROM #__bl_players_team WHERE team_id=" . $row->id . " AND season_id=" . $seasf_id . " AND player_join='0'";
                 $this->db->setQuery($query);
                 $this->db->query();
                 $error = $this->db->getErrorMsg();
                 if ($error) {
                     return JError::raiseError(500, $error);
                 }
             }
             if (count($plzold)) {
                 $sql = count($plzold) > 1 ? "player_id NOT IN (" . implode(",", $plzold) . ")" : "player_id != " . $plzold[0];
                 $query = "DELETE FROM #__bl_players_team WHERE " . $sql . " AND team_id=" . $row->id . " AND season_id=" . $seasf_id . " AND player_join='0'";
                 $this->db->setQuery($query);
                 $this->db->query();
                 $error = $this->db->getErrorMsg();
                 if ($error) {
                     return JError::raiseError(500, $error);
                 }
             }
         }
         //invite unregs
         if (isset($_POST['emlinv']) && count($_POST['emlinv']) && $row->id) {
             for ($p = 0; $p < count($_POST['emlinv']); $p++) {
                 mt_srand((double) microtime());
                 $gen = mt_rand() . "prI" . microtime();
                 $gen = str_replace(" ", "", $gen);
                 $query = "INSERT IGNORE INTO #__bl_players_team(team_id,player_id,season_id,confirmed,invitekey) VALUES(" . $row->id . ",0," . $seasf_id . ",'1','" . $gen . "')";
                 $this->db->setQuery($query);
                 $this->db->query();
                 $error = $this->db->getErrorMsg();
                 if ($error) {
                     return JError::raiseError(500, $error);
                 }
                 $this->InviteUnreg($_POST['emlinv'][$p], $row->t_name, $seasf_id, $gen);
             }
         }
         //action with players join team
         if (isset($_POST['appr_pl']) && count($_POST['appr_pl']) && $row->id) {
             for ($p = 0; $p < count($_POST['appr_pl']); $p++) {
                 $ids = $_POST['appr_pl'][$p];
                 switch ($_POST['action_' . $ids]) {
                     case 1:
                         $this->Pl_Approve($ids, $row->t_name, $row->id, $seasf_id);
                         break;
                     case 2:
                         $this->Pl_Reject($ids, $row->t_name, $row->id, $seasf_id);
                         break;
                 }
                 $query = "INSERT IGNORE INTO #__bl_players_team(team_id,player_id,season_id,confirmed,invitekey) VALUES(" . $row->id . ",0," . $seasf_id . ",'1','" . $gen . "')";
                 $this->db->setQuery($query);
                 $this->db->query();
                 $error = $this->db->getErrorMsg();
                 if ($error) {
                     return JError::raiseError(500, $error);
                 }
                 $this->InviteUnreg($_POST['emlinv'][$p], $row->t_name, $seasf_id, $gen);
             }
         }
     }
     $this->id = $row->id;
 }
示例#2
0
 public function saveTeam()
 {
     $post = JRequest::get('post');
     $mainframe = JFactory::getApplication();
     $post['t_descr'] = JRequest::getVar('t_descr', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post['def_img'] = JRequest::getVar('ph_default', 0, 'post', 'int');
     $post['t_yteam'] = JRequest::getVar('t_yteam', 0, 'post', 'int');
     $row = new JTableTeams($this->db);
     $istlogo = JRequest::getVar('istlogo', 0, 'post', 'int');
     $seasf_id = JRequest::getVar('seasf_id', 0, 'post', 'int');
     if (!$istlogo) {
         $post['t_emblem'] = '';
     }
     if (isset($_FILES['t_logo']['name']) && $_FILES['t_logo']['tmp_name'] != '' && isset($_FILES['t_logo']['tmp_name'])) {
         $bl_filename = strtolower($_FILES['t_logo']['name']);
         $ext = pathinfo($_FILES['t_logo']['name']);
         $bl_filename = "bl" . time() . rand(0, 3000) . '.' . $ext['extension'];
         $bl_filename = str_replace(" ", "", $bl_filename);
         //echo $bl_filename;
         if ($this->uploadFile($_FILES['t_logo']['tmp_name'], $bl_filename)) {
             $post['t_emblem'] = $bl_filename;
         }
     }
     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 = 2 AND ph.cat_id = " . $row->id;
     $this->db->setQuery($query);
     $in_id = $this->db->loadColumn();
     $query = "DELETE FROM #__bl_assign_photos WHERE cat_type = 2 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 . ",2)";
             $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 . ",2)";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     } else {
         if ($_FILES['player_photo_1']['error'] == 1) {
             $mainframe->redirect('index.php?option=com_joomsport&task=team_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 . ",2)";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
     } else {
         if ($_FILES['player_photo_2']['error'] == 1) {
             $mainframe->redirect('index.php?option=com_joomsport&task=team_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 = " . $_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_teams SET bonus_point = " . intval($_POST['bonuses'][$p]) . " WHERE season_id=" . $_POST['sids'][$p] . " AND team_id=" . $row->id;
             $this->db->setQuery($query);
             $this->db->query();
         }
     }
     //-------Players----//
     $assignedPlayers = $_POST['teampl'];
     // $seasf_id = -1 is a friendly match
     $isValidSeason = $seasf_id == -1 || $seasf_id > 0;
     if ($isValidSeason) {
         if ($seasf_id) {
             $query = "DELETE FROM #__bl_players_team WHERE confirmed='0' AND team_id=" . $row->id . " AND season_id=" . $seasf_id;
             $this->db->setQuery($query);
             $this->db->query();
             if (!empty($assignedPlayers)) {
                 for ($p = 0; $p < count($assignedPlayers); $p++) {
                     $query = "INSERT INTO #__bl_players_team(team_id,player_id,season_id) VALUES(" . $row->id . "," . intval($assignedPlayers[$p]) . "," . $seasf_id . ")";
                     $this->db->setQuery($query);
                     $this->db->query();
                 }
             }
         }
     }
     //---add seasons
     if (isset($_POST['seas_all_add']) && count($_POST['seas_all_add'])) {
         for ($p = 0; $p < count($_POST['seas_all_add']); $p++) {
             $query = "INSERT INTO #__bl_season_teams(season_id,team_id) VALUES(" . $_POST['seas_all_add'][$p] . "," . $row->id . ")";
             $this->db->setQuery($query);
             $this->db->query();
         }
     }
     $this->_id = $row->id;
 }
示例#3
0
 function regTeamSave()
 {
     $post = JRequest::get('post');
     unset($post["id"]);
     $user =& JFactory::getUser();
     $row = new JTableTeams($this->db);
     $row->created_by = $user->id;
     $canmore = false;
     $query = "SELECT COUNT(*) FROM #__bl_teams WHERE created_by=" . $user->id;
     $this->db->setQuery($query);
     $curcap = $this->db->loadResult();
     $error = $this->db->getErrorMsg();
     if ($error) {
         return JError::raiseError(500, $error);
     }
     $teams_per_account = $this->getJS_Config('teams_per_account');
     $query = "SELECT COUNT(*) FROM #__bl_moders WHERE uid=" . $user->id;
     $this->db->setQuery($query);
     $teamcap = $this->db->loadResult();
     if ($curcap < $teams_per_account) {
         $canmore = true;
     }
     if ($teamcap < $teams_per_account) {
         $canmore = true;
     }
     if ($user->get('guest') && !$canmore) {
         JError::raiseError(403, JText::_('Access Forbidden'));
         return;
     }
     //$post['captain_id'] = $user->id;
     if (!$row->bind($post)) {
         JError::raiseError(500, $row->getError());
     }
     // Validate and store custom field
     $customFields = JS_Utils::getCustomFields();
     if (!empty($customFields['team_city']['enabled'])) {
         if (!empty($post['cf_team_city'])) {
             $row->t_city = mysql_real_escape_string($post['cf_team_city']);
         } else {
             if (!empty($customFields['team_city']['required'])) {
                 // FIXME: Set a correct error message and redraw form with errors.
                 $this->set_sess(JText::_('BLBE_REQUIRED'), 'error');
                 return;
             }
         }
     }
     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();
     if ($row->id) {
         //-------extra fields-----------//
         if (isset($_POST['extraf']) && count($_POST['extraf'])) {
             foreach ($_POST['extraf'] as $p => $dummy) {
                 $query = "DELETE FROM #__bl_extra_values WHERE f_id = " . $_POST['extra_id'][$p] . " AND uid = " . $row->id;
                 $this->db->setQuery($query);
                 $this->db->query();
                 $error = $this->db->getErrorMsg();
                 if ($error) {
                     return JError::raiseError(500, $error);
                 }
                 if ($_POST['extra_ftype'][$p] == '2') {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue_text) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . addslashes($_POST['extraf'][$p]) . "')";
                 } else {
                     $query = "INSERT INTO #__bl_extra_values(f_id,uid,fvalue) VALUES(" . $_POST['extra_id'][$p] . "," . $row->id . ",'" . $_POST['extraf'][$p] . "')";
                 }
                 $this->db->setQuery($query);
                 $this->db->query();
                 $error = $this->db->getErrorMsg();
                 if ($error) {
                     return JError::raiseError(500, $error);
                 }
             }
         }
         $query = "INSERT INTO #__bl_moders(uid,tid) VALUES({$user->id},{$row->id})";
         $this->db->setQuery($query);
         $this->db->query();
         $error = $this->db->getErrorMsg();
         if ($error) {
             return JError::raiseError(500, $error);
         }
     }
 }