decode($ids[0]); $uid=$hashids->decode($ids[1]); $r=$mysqli->query('CALL getUserNameForBadge('.$uid[0].')'); $res=$r->fetch_assoc(); $badgeName=$res['user_name']; $g='man'; if($ids[2]==1)$g='woman'; $badgeTitle='is a '.$g.' of'; $badgPic="https://".$_SERVER['SERVER_NAME']."/badges/".$cid[0].'_'.$uid[0].'_'.$ids[2].'.jpg'; $badgeUrl="https://".$_SERVER['SERVER_NAME']."/challenge/badge/".$_GET['badge']; } switch(true){ case (strpos($_SERVER['REQUEST_URI'],'opponent')>0): $phase=2; $step=3; if(!(isset($_SESSION['opponent'])||isset($_GET['token'])))header('location:/challenge/'); if(strpos($_SERVER['REQUEST_URI'],'opponent/rate')>0)header('location:/challenge/opponent/read/'); if(isset($_SESSION['opponent'])){ $r=$mysqli->query('CALL checkPhase2('.$_SESSION['opponent']['cid'].')'); if($_SERVER['REMOTE_ADDR'] =='80.178.84.101'){ $rr= $mysqli->query(" SELECT * FROM information_schema.routines "); var_dump($rr->fetch_assoc()); }; $res=$r->fetch_assoc(); if($res['C']==1){ $step=6; } } break; case (strpos($_SERVER['REQUEST_URI'],'challenger')>0): case (strpos($_SERVER['REQUEST_URI'],'results')>0): if((strpos($_SERVER['REQUEST_URI'],'results')>0)){ if(isset($_SESSION['finel'])){ $r=$mysqli->query('CALL checkIfDone('.$_SESSION['finel']['cid'].')'); if($r->num_rows==1){ $res=$r->fetch_assoc(); $message="Challenge was met. Now you get to see just how much you've influenced ".$res['ch']."'s mind "; $subject='Hurray. Perspective Challenge was met'; $url='https://'.$_SERVER['SERVER_NAME'].'/challenge/challenger/finish/'.$_SESSION['finel']['token']; $url_text='See your results'; $to= $res['opMail']; sendEmail($message,$subject,$url,$url_text,$to); $sql="SELECT user_id,ranking FROM `challenge_ranking` WHERE `challenge_id` =".$_SESSION['finel']['cid']; if ($mysqli->more_results())$mysqli->next_result(); $res=mysqli_query($mysqli,$sql); $users=array(); $points=array(); while ($row = mysqli_fetch_array($res)){ array_push($users,$row['user_id']); array_push($points,$row['ranking']); } $mysqli->query('CALL givePointsToUser('. $users[0].','. $points[1].')'); $mysqli->query('CALL givePointsToUser('. $users[1].','. $points[0].')'); mysqli_query($mysqli,"UPDATE `challenge_challenges` SET `finished` = '1' WHERE id= ".$_SESSION['finel']['cid']); } if ($mysqli->more_results())$mysqli->next_result(); } } if (strpos($_SERVER['REQUEST_URI'],'challenger/rate')>0){ $r=$mysqli->query('CALL chackPhase3('.$_SESSION['finel']['cid'].')'); $res=$r->fetch_assoc(); if($res['C']>1){ header('location:/challenge/results/'); die(); } } $phase=3; $step=8; if(isset($_GET['token2']))session_unset(); if(!(isset($_SESSION['finel'])||isset($_GET['token2'])))header('location:/challenge/'); if(strpos($_SERVER['REQUEST_URI'],'challenger/rate')>0)header('location:/challenger/'); if(isset($_SESSION['finel'])){ $r=$mysqli->query('CALL checkPhase2('.$_SESSION['finel']['cid'].')'); $res=$r->fetch_assoc(); if($res['C']==1){ $step=10; if(!strpos($_SERVER['REQUEST_URI'],'results')>0){ if ($mysqli->more_results())$mysqli->next_result(); $r=$mysqli->query('CALL chackPhase3('.$_SESSION['finel']['cid'].')'); $res=$r->fetch_assoc(); if($res['C']>1){ header('location:/challenge/results/'); die(); } } } } break; } $pattern = '/(FacebookExternalHit|GoogleBot)/i'; $agent = $_SERVER['HTTP_USER_AGENT']; if( preg_match($pattern,$agent)){ ?> fetch_assoc(); $url.='opponent/t/'.$_GET['token']; $title='I challenge your perspective on '.$row['category_name'].'. Are you game ?'; } if($badgeName!==''){ $url=$badgeUrl; $img=$badgPic; $h=292; $w=560; } ?> x more_results())$mysqli->next_result(); $result=mysqli_query($mysqli,$SQL); $row = $result->fetch_assoc(); $_SESSION['opponent']['token'] = $token; $_SESSION['opponent']['cid'] = $row['id']; $_SESSION['opponent']['uid'] = $row['uid2']; $r=$mysqli->query('CALL checkPhase2('.$_SESSION['opponent']['cid'].')'); $res=$r->fetch_assoc(); if($res['C']==1){ header('location:/challenge/opponent/finish'); $step=6; die(); } switch(true){ case ($row['accepted']==0): $_SESSION['opponent']['step']=3; header('location:/challenge/opponent/'); break; case ($row['accepted']==1): $_SESSION['opponent']['step']=4; header('location:/challenge/opponent/read/'); break; } $phase=2; die(); } if(isset($_GET['token2'])){ $token=filter_var(mysqli_real_escape_string($mysqli,$_GET['token2']), FILTER_SANITIZE_STRING); $_SESSION['finel']['token'] = $token; $userColumn='uid1'; if(isset($_GET['opponent']))$userColumn='uid2'; $SQL="SELECT ".$userColumn." AS uid, user_name, start_last, t1.id AS cid FROM `challenge_challenges` t1 INNER JOIN challenge_users u ON t1.".$userColumn."=u.id where token='".$token."'"; $result=mysqli_query($mysqli,$SQL); $row = $result->fetch_assoc(); if(is_null($row['start_last']))mysqli_query($mysqli,"UPDATE challenge_challenges SET start_last=NOW() where token='".$token."'" ); foreach($row as $key=>$value)$_SESSION['finel'][$key] = $value; $r=$mysqli->query('CALL chackPhase3('.$_SESSION['finel']['cid'].')'); $res=$r->fetch_assoc(); if($res['C']>1){ header('location:/challenge/results/'); die(); } header('location:/challenge/challenger/read/'); die(); } } ?>