<?php
include("includes/site_info.php");
include('session_handler.inc');
include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$WUserID = $_SESSION['Sess_UserId'];
$folder = $_REQUEST['list_id'];
$mode = $_REQUEST['listvalue'];


if ($mode=="yes") {
$str = $_REQUEST["list_values"];
$sfolder = $_REQUEST["folder"];
$str = substr($str, 3, strlen($str) - 6);
$str_array = explode('\",\"',$str); // turn post into array
$delete_query=mysql_query("DELETE FROM my_friend_folder_list where uid='$WUserID' and folder='$sfolder'",$link) or die(mysql_error());
foreach($str_array as $v)
{
	$j = explode('\":\"',$v);
	if ($j[1]) {
	$id=mysql_result(mysql_query("SELECT id FROM my_friends WHERE uid='$WUserID' and friend_uid='".$j[1]."'"),0);
	$query="INSERT into my_friend_folder_list set fid='$id',uid='$WUserID', friend_uid='".$j[1]."', folder='$sfolder'";
	$result=mysql_query($query,$link) or die(mysql_error());
	}
}
echo '<div align="center">Wow, Your request was done!</strong></div>';
echo "<script>window.top.location.reload();parent.jQuery.facebox.close();</script>";
die;
}

$myhahaper_query=mysql_query("SELECT mem_userid, mem_profileid, mem_username, id FROM my_friends LEFT JOIN members ON (friend_uid=mem_userid) WHERE uid='$WUserID' and approved='1' order by mem_username",$link) or die(mysql_error());

$myfolder_query=mysql_query("SELECT name FROM my_friend_folder WHERE user_id='$WUserID' and folder_id='$folder' limit 1",$link) or die(mysql_error());
$myfolder_TOTAL = mysql_num_rows($myfolder_query);
$myfolder = mysql_fetch_object($myfolder_query);

$default_folder=mysql_fetch_object(mysql_query("SELECT name FROM my_friend_folder WHERE folder_id='$folder' limit 1"));

function getUserList($id, $folder) {
    $result=mysql_query("SELECT * FROM my_friend_folder_list WHERE fid='$id'");
    while ($row = mysql_fetch_assoc($result)){
        if ($row['folder'] == $folder) {
            $check = "checked";
		} 
    }

    if ($check == "checked") {
    	return 'alt="checked"';
	} else {
    	return null;
	}
}

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Wauhaha - Socializer!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="listselection.css" />
<link rel="stylesheet" type="text/css" href="wauhhmain.css" media="screen, print">
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="js/listselection.js"></script>
<script type="text/javascript" src="facebox/facebox.js"></script>
<script type="text/javascript" src="js/instantedit.js"></script>
</head>
<body>
<script type="text/javascript">
setVarsForm("pageID=Edit_Friend_List&userID=<?=$WUserID?>");
</script>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" style="padding:0; margin:0; border:0;">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="white_back_t_xb">
    <?php if ($myfolder_TOTAL > 0){ ?>
    <tr class="grey_14_xb line_height30 padding_lr_5">
      <td><span id="folder_id_<?=$folder?>" class="editText">
        <?=$myfolder->name?>
        </span> <span class="lightgrey_10">Click the folder name to edit it.</span></td>
    </tr>
    <?php } else { ?>
    <tr class="grey_14_xb line_height30 padding_lr_5">
      <td><?=$default_folder->name?></td>
    </tr>
    <?php } ?>
    <tr>
      <td><ul id="list">
          <?php 
	 while ($ret_pic = mysql_fetch_object($myhahaper_query)) {
if ($WUserID==$ret_pic->mem_userid) {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic->mem_userid' and pic_default='Y'") or die(mysql_error()); 
} else {
$photo_query=mysql_query("SELECT * FROM pictures WHERE pic_userid = '$ret_pic->mem_userid' and pic_default='Y' and pic_private='N'") or die(mysql_error()); 
}
$pics_count = mysql_num_rows($photo_query);
$aPicture = mysql_fetch_object($photo_query);
if ($pics_count > 0) {
	$medium = $aPicture->pic_picture."_ps.".$aPicture->ext;
	$male1_picture1 = "$SITE_MAIN_WWW_ROOT/members/$ret_pic->mem_username/picture/$medium";
             }else{
$male1_picture1=$CONST_LINK_ROOT."/".$picture->GetProfilePicture($ret_pic->mem_userid);
}

if ($ret_pic->mem_profileid != null) { $male1_name1= $ret_pic->mem_profileid; }
else { $male1_name1= $ret_pic->mem_username; }

?>
          <li><a href="#" title="<?=ucwords($male1_name1)?>" target="_self" onClick="return false"><span 
class="square" style="background-image: 
url(<?=$male1_picture1?>);"><span></span></span><strong>
            <?=ucwords($male1_name1)?>
            </strong></a>
            <input type="hidden" name="list_value[]" value="<?=$ret_pic->mem_userid?>" class="fix_button" <?=getUserList($ret_pic->id, $folder)?>/>
          </li>
          <? 
				$i++;
				} ?>
        </ul></td>
    </tr>
    <tr>
      <td><input type="hidden" name="folder" value="<?=$folder?>" />
        <input type="hidden" name="listvalue" value="yes" /></td>
    </tr>
  </table>
</form>
<script type="text/javascript" language="JavaScript">
    $(document).ready(function() {
      //id(ul id),width,height(element height),row(elements in row)        
      $.ListSelection("#list","420","64","3");
    });    
</script>
</body>
</html>
