<?php

include("../includes/site_config.php");
//include('demo.php');
include('../session_handler.inc');

/*if ($Sess_UserType != "A") {
	exit;
}*/

$genders = array('M' => PRGSTATS_MALES, 'F' => PRGSTATS_FEMALES);



###################

# Code for chart starts

##################
	
	
$show_label = true; // true = show label, false = don't show label.
$show_percent = true; // true = show percentage, false = don't show percentage.
$show_text = true; // true = show text, false = don't show text.
$show_parts = false; // true = show parts, false = don't show parts.
$label_form = 'square'; // 'square' or 'round' label.
$width = 300;

$background_color = 'FFFFFF'; // background-color of the chart...
$text_color = '000000'; // text-color.
$colors = array('7BEFFE', 'FE9E2D', '7F99B2','F7EFC6', 'C6BE8C', 'CC6600','990000','520000','BFBFC1','808080'); // colors of the slices.
$shadow_height = 16; // Height on shadown.
$shadow_dark = true; // true = darker shadow, false = lighter shadow...
//$c_perc= 5;



// DON'T CHANGE ANYTHING BELOW THIS LINE...
$query="SELECT COUNT(mem_sex) as gender_total, mem_sex FROM members GROUP BY mem_sex";
$retval=mysql_query($query,$link) or die(mysql_error());
while($reg_stats=mysql_fetch_object($retval)) {
        switch ($reg_stats->mem_sex) {
                case 'F':
                         $f_perc=$reg_stats->gender_total;
                           
                        break;
                case 'M':
                        $m_perc=$reg_stats->gender_total;
                          
                        break;
                case 'C':
                        $c_perc=$reg_stats->gender_total;
       					
						break;
        }
}


$data=$f_perc.'*'.$m_perc;


//echo "<br>";


//$data="10*9*11";
$label="Female*Males";

//$data = $_GET["data"];
//$label = $_GET["label"];

//$height = $width/2;
$height = 200;
$data = explode('*',$data);

if ($label != '') $label = explode('*',$label);

for ($i = 0; $i < count($label); $i++) 
{
	if ($data[$i]/array_sum($data) < 0.1) $number[$i] = ' '.number_format(($data[$i]/array_sum($data))*100,1,',','.').'%';
	else $number[$i] = number_format(($data[$i]/array_sum($data))*100,1,',','.').'%';
	if (strlen($label[$i]) > $text_length) $text_length = strlen($label[$i]);
}

if (is_array($label))
{
$antal_label = count($label);
$xtra = (5+15*$antal_label)-($height+ceil($shadow_height));
if ($xtra > 0) $xtra_height = (5+15*$antal_label)-($height+ceil($shadow_height));

$xtra_width = 5;
if ($show_label) $xtra_width += 20;
if ($show_percent) $xtra_width += 45;
if ($show_text) $xtra_width += $text_length*8;
if ($show_parts) $xtra_width += 35;
}

$img = ImageCreateTrueColor($width+$xtra_width, $height+ceil($shadow_height)+$xtra_height);

ImageFill($img, 0, 0, colorHex($img, $background_color));

foreach ($colors as $colorkode) 
{
	$fill_color[] = colorHex($img, $colorkode);
	$shadow_color[] = colorHexshadow($img, $colorkode, $shadow_dark);
}

$label_place = 5;

if (is_array($label))
{
for ($i = 0; $i < count($label); $i++) 
{
	if ($label_form == 'round' && $show_label)
	{
		imagefilledellipse($img,$width+11,$label_place+5,10,10,colorHex($img, $colors[$i % count($colors)]));
		imageellipse($img,$width+11,$label_place+5,10,10,colorHex($img, $text_color));
	}
	else if ($label_form == 'square' && $show_label)
	{	
		imagefilledrectangle($img,$width+6,$label_place,$width+16,$label_place+10,colorHex($img, $colors[$i % count($colors)]));
		imagerectangle($img,$width+6,$label_place,$width+16,$label_place+10,colorHex($img, $text_color));
	}

	if ($show_percent) $label_output = $number[$i].' ';
	if ($show_text) $label_output = $label_output.$label[$i].' ';
	if ($show_parts) $label_output = $label_output.$data[$i];

	imagestring($img,'2',$width+20,$label_place,$label_output,colorHex($img, $text_color));
	$label_output = '';

	$label_place = $label_place + 15;
}
}
$centerX = round($width/2);
$centerY = round($height/2);
$diameterX = $width-4;
$diameterY = $height-4;

$data_sum = array_sum($data);

$start = 270;

for ($i = 0; $i < count($data); $i++) 
{
	$value += $data[$i];
	$end = ceil(($value/$data_sum)*360) + 270;
	$slice[] = array($start, $end, $shadow_color[$value_counter % count($shadow_color)], $fill_color[$value_counter % count($fill_color)]);
	$start = $end;
	$value_counter++;
}

for ($i=$centerY+$shadow_height; $i>$centerY; $i--) 
{
	for ($j = 0; $j < count($slice); $j++)
	{
		if ($slice[$j][0] != $slice[$j][1]) ImageFilledArc($img, $centerX, $i, $diameterX, $diameterY, $slice[$j][0], $slice[$j][1], $slice[$j][2], IMG_ARC_PIE);
	}
}	

for ($j = 0; $j < count($slice); $j++)
{
	if ($slice[$j][0] != $slice[$j][1]) ImageFilledArc($img, $centerX, $centerY, $diameterX, $diameterY, $slice[$j][0], $slice[$j][1], $slice[$j][3], IMG_ARC_PIE);
}

OutputImage($img);
/*// Create a blank image and add some text
$img = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($img, 233, 14, 91);
imagestring($img, 1, 5, 5, 'A Simple Text String', $text_color);

// Save the image as 'simpletext.jpg'
imagejpeg($img, 'simpletext.jpg');

// Free up memory
imagedestroy($img);


*/
ImageDestroy($img);


function colorHex($img, $HexColorString) 
{
		$R = hexdec(substr($HexColorString, 0, 2));
		$G = hexdec(substr($HexColorString, 2, 2));
		$B = hexdec(substr($HexColorString, 4, 2));
		return ImageColorAllocate($img, $R, $G, $B);
}

function colorHexshadow($img, $HexColorString, $mork) 
{
	$R = hexdec(substr($HexColorString, 0, 2));
	$G = hexdec(substr($HexColorString, 2, 2));
	$B = hexdec(substr($HexColorString, 4, 2));

	if ($mork)
	{
		($R > 99) ? $R -= 100 : $R = 0;
		($G > 99) ? $G -= 100 : $G = 0;
		($B > 99) ? $B -= 100 : $B = 0;
	}
	else
	{
		($R < 220) ? $R += 35 : $R = 255;
		($G < 220) ? $G += 35 : $G = 255;
		($B < 220) ? $B += 35 : $B = 255;				
	}			
	
	return ImageColorAllocate($img, $R, $G, $B);
}

function OutputImage($img) 
{
	
	imagejpeg($img, 'simpletext.jpg', 100);
}





##############
# Chart code ends
##############










# retrieve the template
$area = 'member';


#####################QUERY FOR NEW TABLE ADDED###############################
include_once __INCLUDE_CLASS_PATH."/class.Gallery.php";
$gallery= new Gallery();
$totalpengallery = $gallery->CountPendingItem();

$query="SELECT COUNT(mem_userid) FROM members";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalreg=mysql_result($retval,0,0);
$query="SELECT COUNT(adv_userid) FROM adverts";
$retval=mysql_query($query,$link) or die(mysql_error());
$totaladv=mysql_result($retval,0,0);

$query="SELECT COUNT(mem_sex) as gender_total, mem_sex FROM members GROUP BY mem_sex";
$retval=mysql_query($query,$link) or die(mysql_error());

$query="SELECT COUNT(mem_expiredate) FROM members WHERE mem_expiredate >= NOW()";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalprem=mysql_result($retval,0,0);

$query="SELECT COUNT(mem_expiredate) FROM members WHERE mem_expiredate < NOW()";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalstand=mysql_result($retval,0,0);

$query="SELECT COUNT(adv_approved) FROM adverts WHERE adv_approved = 1";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalapp=mysql_result($retval,0,0);

$retval=mysql_query($query,$link) or die(mysql_error());
$totalpenforum=mysql_result($retval,0,0);

$query = "  SELECT COUNT(com_approved)
            FROM profile_comment
                WHERE com_approved = '0'";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalpencomment=mysql_result($retval,0,0);

$query = "  SELECT COUNT(adv_approved) FROM adverts

                LEFT JOIN members ON (adv_userid=mem_userid)

            WHERE adv_approved = 0 AND mem_confirm = 1";

$retval=mysql_query($query,$link) or die(mysql_error());
$totalpen=mysql_result($retval,0,0);

$query="SELECT COUNT(adv_approved) FROM adverts WHERE adv_approved = 2";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalrej=mysql_result($retval,0,0);

$query="SELECT COUNT(mem_confirm) FROM members WHERE mem_confirm = 1";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalcon=mysql_result($retval,0,0);

$query="SELECT COUNT(mem_confirm) FROM members WHERE mem_confirm = 0";
$retval=mysql_query($query,$link) or die(mysql_error());
$totaluncon=mysql_result($retval,0,0);

$query="SELECT COUNT(ev_approved) FROM events WHERE ev_approved=0";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalevapproved=mysql_result($retval,0,0);

$query="SELECT COUNT(review_approved) FROM reviews WHERE review_approved=0";
$retval=mysql_query($query,$link) or die(mysql_error());
$totalreviewapproved=mysql_result($retval,0,0);

$query="SELECT COUNT(mem_userid) FROM members where mem_sex='M'";
$retsex=mysql_query($query,$link) or die(mysql_error());
$totalsexm=mysql_result($retsex,0,0);

$query="SELECT COUNT(mem_userid) FROM members where mem_sex='F'";
$retsex=mysql_query($query,$link) or die(mysql_error());
$totalsexf=mysql_result($retsex,0,0);


$time=time();
$timeout = time()-$sesstime*60;
$query="SELECT COUNT(mem_userid) FROM members where timestamp > $timeout";
$reton=mysql_query($query,$link) or die(mysql_error());
$totalon=mysql_result($reton,0,0);


$query="SELECT COUNT(pic_id) FROM pictures";
$retpic=mysql_query($query,$link) or die(mysql_error());
$totalpic=mysql_result($retpic,0,0);

$query="SELECT COUNT(pic_id) FROM pictures where approved='0'";
$retpicapp=mysql_query($query,$link) or die(mysql_error());
$totalpicapp=mysql_result($retpicapp,0,0);

$query="SELECT COUNT(msg_id) FROM messages";
$retmes=mysql_query($query,$link) or die(mysql_error());
$totalmes=mysql_result($retmes,0,0);

$query="SELECT COUNT(vid_id) FROM videos";
$retvid=mysql_query($query,$link) or die(mysql_error());
$totalvid=mysql_result($retvid,0,0);

$query="SELECT COUNT(msg_id) FROM messages where msg_title='Someone is flirting with you.'";
$retflrt=mysql_query($query,$link) or die(mysql_error());
$totalflrt=mysql_result($retflrt,0,0);

$query="SELECT COUNT(aud_id) FROM audios where approved='0'";
$retaudio=mysql_query($query,$link) or die(mysql_error());
$totalaudio=mysql_result($retaudio,0,0);

$query="SELECT COUNT(bio_approved) FROM adverts where adv_bio !='' AND bio_approved='0'";
$retbio=mysql_query($query,$link) or die(mysql_error());
$totalbio=mysql_result($retbio,0,0);

$query="SELECT COUNT(ev_eventid) FROM events";
$retevent=mysql_query($query,$link) or die(mysql_error());
$totalevent=mysql_result($retevent,0,0);

$query="SELECT COUNT(news_id) FROM news";
$retnews=mysql_query($query,$link) or die(mysql_error());
$totalnews=mysql_result($retnews,0,0);

$query="SELECT COUNT(story_id) FROM stories";
$retstory=mysql_query($query,$link) or die(mysql_error());
$totalstory=mysql_result($retstory,0,0);


################END OF TABLE QUERY#############################


?>
<?php include("include/header.php"); ?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Demographics</div></div>
<div class="clear"></div>
<div class="admin-page">

  <table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="center" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
   
    <tr>
      <td><table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
	  <tr> 
	  <td align="center" valign="top">
	  <img src="simpletext.jpg">
	  </td></tr>
<td>&nbsp;</td>
<tr><td>&nbsp;</td></tr>
	  <table width="100%"  border="0" cellspacing="0" cellpadding="0" >
<tr><td>
      <!--DWLayoutTable

      <tr>

         <td height="0" align="center" ></td>

       </tr>

       <tr valign="top">


        <td align="left" ><table width="100%"  border="0" cellspacing="<?php //print("$CONST_SUBTABLE_CELLSPACING"); ?>" cellpadding="<?php //print("$CONST_SUBTABLE_CELLPADDING"); ?>">-->
               
<br /><br />
          <?php /*?><td align="left" valign="top" class="tdhead"  colspan="4"></td>
        </tr>
        <tr>
          <td align="left" class="normal" colspan="4"></td>
        </tr>

        <?php
					echo '
						<tr class="normal" >
							<td  align="left">&nbsp;</td>';
								reset($genders);
								while(list($gender_short, $gender) = each($genders))
								{
									echo '<td  align="left"><b>'.$gender.'</b></td>';
									eval("\$total_count$gender_short = 0;");
								}
								echo '</tr>';

								$genders2 = $genders;
								reset($genders);
								while(list($gender_short, $gender) = each($genders))
								{
									echo '
										<tr class="normal" >

											<td  align="left"><b>'.$gender.'</b></td>';
									reset($genders2);
									while(list($gender_short2, $gender2) = each($genders2))
									{
										switch($gender_short2)
										{
											case 'M': $seek = 'adv_seekmen'; break;
											case 'F': $seek = 'adv_seekwmn'; break;
											default:  $seek = 'adv_seekcpl';
										}
										$retval = mysql_query("SELECT COUNT(*) FROM adverts WHERE adv_sex = '$gender_short' AND $seek = 'Y'", $link);
										$count = mysql_result($retval,0,0);
										echo '
												<td  align="left">'.$count.'</td>';
										eval("\$total_count$gender_short2 += $count;");
									}
									echo '</tr>';
								}

								echo '
									<tr class="normal" >

										<td  align="left"><b>'.PRGSTATS_TOTALS.'</b></td>';
								reset($genders);
								while(list($gender_short, $gender) = each($genders))
								{
									echo '<td  align="left">'.eval("return \$total_count$gender_short;").'</td>';
								}
								echo '</tr>';
				?>

        <tr>
          <td align="left"  valign="top" class="tdfoot" colspan="4">&nbsp;</td><?php */?>
        </tr>
        <tr>
          <td align="left"  valign="top" class="admin-head" colspan="4"></td>
        </tr>
        <tr>
          <td  valign="top" align="left" class="normal" colspan="4"><?php echo PRGSTATS_RPB_HELP ?></td>
        </tr>
        <tr>
          <td align="left" class="normal" colspan="4"> <table width="100%"  border="0" cellspacing="$CONST_SUBTABLE_CELLSPACING" cellpadding="3" >
              <tr>
                <td valign="top" align="left" width="20" ></td>
                <td  align="left"></td>
                <td  align="left" class="admin-head2"><?php echo PRGSTATS_REGISTERED?></td>
                <td  align="left" class="admin-head2" ><?php echo PRGSTATS_AD1?></td>
                <td  align="left"></td>
              </tr>
              <tr>
                <td colspan="2">
                  <?php
							reset($genders);
							$total_reg_count = 0;
							$total_adv_count = 0;
							while(list($gender_short, $gender) = each($genders))
							{
								echo '
									<tr>
										<td valign="top" align="left"></td>
										<td  align="left"><b>'.$gender.'</b></td>';
								$retval = mysql_query("SELECT COUNT(*) FROM members WHERE mem_sex = '$gender_short'", $link);
								$reg_count = mysql_result($retval,0,0);
								$retval = mysql_query("SELECT COUNT(*) FROM adverts WHERE adv_sex = '$gender_short'", $link);
								$adv_count = mysql_result($retval,0,0);
								echo '
										<td  align="left">'.$reg_count.'</td>
										<td  align="left">'.$adv_count.'</td>
										<td  align="left"></td>
									</tr>';
								$total_reg_count += $reg_count;
								$total_adv_count += $adv_count;
							}
						?>
                </td>
              </tr>
              <tr>
                <td valign="top" align="left" width="20"></td>
                <td align="left" ><b><?php echo PRGSTATS_TOTALS?></b></td>
                <td align="left" >
                  <?=$total_reg_count?>
                </td>
                <td align="left" >
                  <?=$total_adv_count?>
                </td>
                <td align="left" ></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td align="left" valign="top" class="tdfoot" colspan="4">&nbsp;</td>
        </tr>
        <tr>
          <?php /*?><td align="left" valign="top" class="tdhead" colspan="4"><?php echo PRGSTATS_AGE?></td>
        </tr>
        <tr>
          <td valign="top" align="left"  class="normal" colspan="4"><?php echo PRGSTATS_AGE_HELP?></td>
        </tr>
        <tr>
          <td align="left" valign="top" class="normal"  colspan="4">
		  <table width="100%"  border="0" cellspacing="$CONST_SUBTABLE_CELLSPACING" cellpadding="3" >
              <tr>
                <td >&nbsp;</td>
                <td  align="center"><strong>&lt;= 20</strong></td>
                <td  align="center"><strong>21 - 30 </strong></td>
                <td  align="center"><strong>31 - 40 </strong></td>
                <td  align="center"><strong>41 - 50 </strong></td>
                <td  align="center"><strong>51 - 60 </strong></td>
                <td  align="center"><strong>61 - 70 </strong></td>
                <td  align="center"><strong>&gt; 70 </strong></td>
              </tr>
              <?php
					reset($genders);
					while(list($gender_short, $gender) = each($genders))
					{
						echo'
							<tr>
								<td width="12%" ><strong>'.$gender.'</strong></td>';
						for($gender_max = 20; $gender_max <= 80; $gender_max += 10)
						{
							switch($gender_max)
							{
								case 20: $sql_cond = '< 20'; break;
								case 80: $sql_cond = '> 70'; break;
								default: $sql_cond = 'BETWEEN '.($gender_max-9).' AND '.$gender_max; break;
							}
							$query = "SELECT count(*) AS `count` FROM members WHERE (YEAR(CURDATE())-YEAR(mem_dob)) - (RIGHT(CURDATE(),5) < RIGHT(mem_dob,5)) $sql_cond AND mem_sex = '$gender_short'";
							$retval = mysql_query($query,$link);
							$result = mysql_fetch_object($retval);
							$count = $result->count;
							echo '<td width="12%"  align="center">'.$count.'</td>';
						}
						echo '</tr>';
					}
				?>
            </table></td><?php */?>
        </tr>
        <tr>
          <td valign="top" align="left" ></td>
        </tr>
      </table></td>
    </tr>
</table></div><div class="admin-page-bottom"></div></div>
<?php include("include/footer.php"); ?>