Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Trade Proposal Popup, For 2008
habman
post Sep 2 2008, 06:38 AM
Post #1


Veteran
***

Group: Members
Posts: 1948
Joined: 29-August 05
From: Leamington ON, Canada
Member No.: 3058

2009 MFL: 31589 , 24836


PLEASE SEE THIS TOPIC FOR A BETTER POPUP

http://www.sidelineleagues.com/forums/inde...showtopic=23192

===============================================================

I have reworked my trade proposal popup so that it should now work only once per browser session.

This script will:

- Alert owners of outstanding trade proposals made to them
- Alert owners of outstanding trade proposals made by them (can be turned off if desired)
- Alert owners of a trade requiring them to cast their vote
- Alert commissioners of a trade awaiting their review (can be turned off if desired)

I have tested it in IE and Firefox. In IE it works without any problems in Firefox it seems to work only when the code is near the top of the page(haven't figured out why yet).

In order to implement this app simply copy and paste the following code into a Home Page Module then add the home page module to your list of home page modules to display.

Hint: You can add this code to any home page module even one that is currently in use. Just try to add it to one that comes at or near the top of your home page modules being displayed.

CODE
<script language="JavaScript" type="text/javascript">
<!--

if (franchise_id==undefined) { // Check to see if user is not logged in
  var franchise_id;
} else {

// alert commissioner that a trade is awaiting review 'on/off'
var commishAlert = 'on';

// alert owners that they have an outstanding proposal 'on/off'
var proposals = 'on';


// NO NEED TO CHANGE ANYTHING BELOW THIS LINE

var tradePopupCookie = "tradePopupCookie_" + league_id + "_" + franchise_id;


if (document.cookie.length > 0) {
  if (document.cookie.indexOf(tradePopupCookie + "=popped;") == -1) { // Then cookie does not exist so create cookie and load iframe
    document.write('<iframe src="http://www.habman.com/mfl/apps/tradePopup.php?leagueid=%LEAGUEID%&amp;year=%YEAR%&amp;host=%HOST%&amp;franchise_id=' + franchise_id + '&amp;proposals=' + proposals + '&amp;commish_alert=' + commishAlert + '" scrolling="no" height="0" width="0" frameborder="0"></iframe>');
    document.cookie=tradePopupCookie+"=popped;";
  }
}
}

// -->
</script>


--------------------
My MFL scripts . . . . . . . . http://www.habman.com/mfl/
Go to the top of the page
 
+Quote Post
habman
post Sep 2 2008, 06:43 AM
Post #2


Veteran
***

Group: Members
Posts: 1948
Joined: 29-August 05
From: Leamington ON, Canada
Member No.: 3058

2009 MFL: 31589 , 24836


For those interested this is how the code works.

Hopefully someone can find a way to improve the script because I am sure there is room for improvement.


The javascript above first checks to see if the user viewing the page is logged in by checking the var franchise_id. If they are not logged in then nothing happens.

If they are logged in then it checks to see if a cookie has been set. If it has been set then nothing happens.

If it hasn't been set then the script loads an invisible iframe and sets the session cookie.

The iframe is a php script that contains the following:
CODE
<?

$leagueid      = $_GET['leagueid'];
$year          = $_GET['year'];
$host          = $_GET['host'];
$franchise_id  = $_GET['franchise_id'];
$proposals     = $_GET['proposals'];
$commish_alert = $_GET['commish_alert'];


$url="http://".$host."/";
$url=ereg_replace("www","football",$url);

if($url=="") exit();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>MFL Trade Proposal Popup</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<script language="JavaScript" type="text/javascript">
<!--

function loadpopup(whichOne){
switch(whichOne) {
  case '1' : { alert ("A trade proposal has been offered to you.\n\n  Click 'OK' then go to menu item FOR OWNERS>TRADES to view proposal."); break; }
  case '2' : { alert ("A trade is awaiting your review.\n\n  Click 'OK' then go to menu item FOR COMMISSIONER>REVIEW TRADES to review trade."); break; }
  case '3' : { alert ("A trade is awaiting a league-wide vote.\n\n  Click 'OK' then go to menu item COMMUNICATIONS>LEAGUE POLLS to submit your vote."); break; }
  case '4' : { alert ("You have an outstanding trade offer.\n\n  Click 'OK' then go to menu item FOR OWNERS>TRADES to view proposal."); break; }
}
}

// -->
</script>
</head>

<?
$body="<body onload=\"";
if($franchise_id!="") {
  $embedfile = $url.$year."/embed?L=".$leagueid."&MODULE=TRADES&FRANCHISE=$franchise_id";
  $str = file_get_contents($embedfile);

  if($franchise_id!="0000") { // NOT COMMISSIONER SO CHECK FOR TRADE PROPOSAL

   if(!preg_match("|0 trades proposed by others to me|",$str)&&preg_match("|trades proposed by others to me|",$str)) {
    $body .= "loadpopup('1');";
   }
   if(!preg_match("|0 trades proposed by me to others|",$str)&&preg_match("|trades proposed by me to others|",$str)&&$proposals!="off") {
    $body .= "loadpopup('4');";
   }
  } else {                    // IS COMMISIONER SO CHECK FOR TRADES AWAITING REVIEW
   if(!preg_match("|0 trades|",$str)&&preg_match("|Trades Awaiting Your Review|",$str)&&$commish_alert!="off") {
    $body .= "loadpopup('2');";
   }
  }

}//END IF

$embedfile = $url.$year."/options?L=".$leagueid."&O=69";
$str = file_get_contents($embedfile);

if(!preg_match("|Reject:|",$str)&&preg_match("|Reject|",$str)) {
  $body.= "loadpopup('3');";
}

$body.="\">";
print "$body";
?>


</body>
</html>


What the php script does is uses mfl's embed program to load the TRADES module then screenscrapes to check for specific words to determine whether a team has an outstanding proposal or not.

I know "screenscrape" might be a bad word for some but it seems to work in this instance.

It uses a similar method to see if a trade is awaiting review but it loads up the polls page (O=69) and screenscrapes to look for the word "reject". This part of the script could fail if a franchise has the word "Reject" in their team name.

Hopefully someone can find something that I missed that can improve this app.


BTW the big difference between this new script and my first script was that I am now setting the cookie through MFL's site in the javascript above rather then in the php iframe which I am pretty sure was being blocked in many instances and that is why the code popped up on each page reload.


--------------------
My MFL scripts . . . . . . . . http://www.habman.com/mfl/
Go to the top of the page
 
+Quote Post
FFTL
post Sep 2 2008, 06:49 AM
Post #3


Veteran
***

Group: Members
Posts: 170
Joined: 15-August 08
From: Baltimore
Member No.: 6812

2009 MFL: 20271
2010 MFL: 40665 , 23392


Great job habman!

Also did you get my email last week?


--------------------
Damien Clark
rosterdoc.com
Go to the top of the page
 
+Quote Post
habman
post Sep 2 2008, 07:13 AM
Post #4


Veteran
***

Group: Members
Posts: 1948
Joined: 29-August 05
From: Leamington ON, Canada
Member No.: 3058

2009 MFL: 31589 , 24836


QUOTE (FFTL @ Sep 2 2008, 08:49 AM) *
Great job habman!

Also did you get my email last week?


Thanks.

I'm sure that I did receive your e-mail but I have received quite a few e-mails and quite a few PM's that I haven't had a chance to reply to most of them. Sorry about that.


--------------------
My MFL scripts . . . . . . . . http://www.habman.com/mfl/
Go to the top of the page
 
+Quote Post
smithktff
post Sep 2 2008, 07:21 AM
Post #5


Veteran
***

Group: Validating
Posts: 2651
Joined: 12-July 04
Member No.: 708



habman, not sure if you are aware of this or not, but several classes were added to the trades module to indicate whether trades are pending. You should be able to use these to test these conditions, rather than screen scraping. See this thread:

http://forums.myfantasyleague.com/forums/i...showtopic=21992
Go to the top of the page
 
+Quote Post
FFTL
post Sep 2 2008, 07:23 AM
Post #6


Veteran
***

Group: Members
Posts: 170
Joined: 15-August 08
From: Baltimore
Member No.: 6812

2009 MFL: 20271
2010 MFL: 40665 , 23392


QUOTE (habman @ Sep 2 2008, 09:13 AM) *
QUOTE (FFTL @ Sep 2 2008, 08:49 AM) *
Great job habman!

Also did you get my email last week?


Thanks.

I'm sure that I did receive your e-mail but I have received quite a few e-mails and quite a few PM's that I haven't had a chance to reply to most of them. Sorry about that.


No problem, that is what I figured. smile.gif


--------------------
Damien Clark
rosterdoc.com
Go to the top of the page
 
+Quote Post
habman
post Sep 2 2008, 07:37 AM
Post #7


Veteran
***

Group: Members
Posts: 1948
Joined: 29-August 05
From: Leamington ON, Canada
Member No.: 3058

2009 MFL: 31589 , 24836


QUOTE (smithktff @ Sep 2 2008, 09:21 AM) *
habman, not sure if you are aware of this or not, but several classes were added to the trades module to indicate whether trades are pending. You should be able to use these to test these conditions, rather than screen scraping. See this thread:

http://forums.myfantasyleague.com/forums/i...showtopic=21992

No I wasn't aware of that. I have been out of the loop for most of the off-season.

Thanks.

BTW I read through the thread and know that you are not a fan of popups (neither am I and I actually don't use this app). Since I don't use the app myself I wasn't aware that my cookie to have the popup appear only once per browser session wasn't working. The way I am doing the cookie now should resolve that issue.


--------------------
My MFL scripts . . . . . . . . http://www.habman.com/mfl/
Go to the top of the page
 
+Quote Post
Ogre
post Sep 2 2008, 08:09 AM
Post #8


Veteran
***

Group: Members
Posts: 179
Joined: 27-April 08
From: PA
Member No.: 6387



your the best habman. I have been waiting for another owner to review my trade that I offered him and he is like I don't see anything, I added this code and had him logout then log back in and sure enough he saw the popup.

Thanks again mang!
Go to the top of the page
 
+Quote Post
jwh_43
post Sep 3 2008, 03:27 PM
Post #9


Veteran
***

Group: Members
Posts: 129
Joined: 23-February 04
From: South Carolina
Member No.: 41

2009 MFL: 14078


Habman, I copied and pasted the code and it doesn't work for me for what ever reason. When you get the time can you tell me what I am doing wrong? Thanks in advance.
Go to the top of the page
 
+Quote Post
jwh_43
post Sep 3 2008, 03:33 PM
Post #10


Veteran
***

Group: Members
Posts: 129
Joined: 23-February 04
From: South Carolina
Member No.: 41

2009 MFL: 14078


QUOTE (jwh_43 @ Sep 3 2008, 04:27 PM) *
Habman, I copied and pasted the code and it doesn't work for me for what ever reason. When you get the time can you tell me what I am doing wrong? Thanks in advance.


Never mind...I kept working with it and got it to work. Thanks a million for all of your hard work!!!
Go to the top of the page
 
+Quote Post
magic6
post Sep 5 2008, 08:48 AM
Post #11


Veteran
***

Group: Members
Posts: 40
Joined: 2-August 08
Member No.: 6698

2009 MFL: 27243


Can this be added to a header or footer?
Go to the top of the page
 
+Quote Post
habman
post Sep 5 2008, 09:00 AM
Post #12


Veteran
***

Group: Members
Posts: 1948
Joined: 29-August 05
From: Leamington ON, Canada
Member No.: 3058

2009 MFL: 31589 , 24836


QUOTE (magic6 @ Sep 5 2008, 10:48 AM) *
Can this be added to a header or footer?

Yes I can't see any reason why not.


--------------------
My MFL scripts . . . . . . . . http://www.habman.com/mfl/
Go to the top of the page
 
+Quote Post
gobrowns
post Sep 15 2008, 04:36 PM
Post #13


Veteran
***

Group: Members
Posts: 40
Joined: 8-July 07
Member No.: 5293



Any reason why my trade popup isn't working? It is in HPM #1 and it is on my main page.
Go to the top of the page
 
+Quote Post
habman
post Sep 15 2008, 05:05 PM
Post #14


Veteran
***

Group: Members
Posts: 1948
Joined: 29-August 05
From: Leamington ON, Canada
Member No.: 3058

2009 MFL: 31589 , 24836


QUOTE (gobrowns @ Sep 15 2008, 06:36 PM) *
Any reason why my trade popup isn't working? It is in HPM #1 and it is on my main page.



Not sure why it is not working for you. Everything seems to be in order.

Could it be that you are logged in as the commissioner and not your own franchise?

Try logging in as your franchise to see if a popup occurs.

BTW This link created by the app for your league is working for Franchise #4

http://www.habman.com/mfl/apps/tradePopup....ommish_alert=on


--------------------
My MFL scripts . . . . . . . . http://www.habman.com/mfl/
Go to the top of the page
 
+Quote Post
FFTL
post Sep 15 2008, 06:13 PM
Post #15


Veteran
***

Group: Members
Posts: 170
Joined: 15-August 08
From: Baltimore
Member No.: 6812

2009 MFL: 20271
2010 MFL: 40665 , 23392


QUOTE (habman @ Sep 15 2008, 07:05 PM) *
QUOTE (gobrowns @ Sep 15 2008, 06:36 PM) *
Any reason why my trade popup isn't working? It is in HPM #1 and it is on my main page.



Not sure why it is not working for you. Everything seems to be in order.

Could it be that you are logged in as the commissioner and not your own franchise?

Try logging in as your franchise to see if a popup occurs.

BTW This link created by the app for your league is working for Franchise #4

http://www.habman.com/mfl/apps/tradePopup....ommish_alert=on


Habman, its not working for me either.. Does mine look right?


--------------------
Damien Clark
rosterdoc.com
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 3rd September 2010 - 11:49 PM