SHOWING MEMBER VIDEOS ON A MEMBER’S PAGE - Apr 23rd, 2011
|
A client of mine who runs a dance school wanted to be able to create personalized videos for her students. She wanted each student who paid to have a video created to be able to see only their video.
Implementing this was made easier, because I was already using the “website membership” plugin and all students were also “members”.
NOTE: I had created 2 new text fields in the “accounts” table, “last_name’ and “first_name” when I set up the CMSB installation, so that I could address each student by their name. I’ll use these fields for this recipe also.
Here’s how:
1) First I added a “videos_for_sale” check box field to the “accounts” user account section.
2) Next I created a multi-record section called Videos For Sale”. Under the Viewer URL tab, set the detail page URL to /videosdetail.php
Delete the “content” field and add 4 additional fields to the editor for a total of 5 input fields ("title" is the 5th) A) An “upload” field called “video_uploads”, restricted to one mp4 or mov upload of unlimited size, with no thumbnails. B) An “upload” field called “background_image” for an optional placeholder image while the video is loading. C) A “text box” field called “description” D) A pull down “list” field
The only field that’s a bit special is the list field. Instead of listing all the student’s names, I wanted to restrict the pull down to show only the last name of those students (members) that had a video created for them (a check mark in the “video_for_sale” check box in their account record).
Set the List Options pull down to “Get options from MySQL query” replace the sample code in the box below to this:
SELECT num, last_name FROM '<?php echo $TABLE_PREFIX ?>accounts' WHERE video_for_sale='1'
This will populate the pull down list with the last_names from only those records with a check mark (1) in the “videos_for_sale” field in the “accounts” table.
After saving the new editor, check a few check boxes in the "accounts" records and create a few test records in the "videos_for_sale" editor and upload a few test videos (preferably in .mp4 format)
NOTE: You may have to change the maximum upload and maximum post sizes in your web server's PHP.ini file to allow for large uploads. (They're normally set to less than 10 Mb by default)
Now for the viewers.
On what I called the students page (students.php), include the following code. This will show a set of links to the video if one exists for that member:
In the head of this page, after the "load viewer library" call, add this "load records" call:
// load records list($videos_for_saleRecords, $videos_for_saleMetaData) = getRecords(array( 'tableName' => 'videos_for_sale', ));
Note: If you are pulling information from a single record editor on this page as well, you’ll have to remove the 'where' => whereRecordNumberInUrl(1), line from the load records call.
And this error message call:
<?php if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); } ?>
And in the body:
<!-- USER LOGIN FORM --> <?php if (@$errorsAndAlerts): ?> <div class="your_class"> <br /> <?php echo $errorsAndAlerts; ?> <br /> </div> <?php endif ?>
<?php if (!@$CURRENT_USER): ?> <form action="?" method="post"> <input type="hidden" name="action" value="login" />
<table width="400" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td class="your-class">Username</td> <td><input type="text" name="username" value="<?php echo htmlspecialchars(@$_REQUEST['username']); ?>" size="20" /></td> </tr> <tr> <td class="your_class">Password</td> <td><input type="password" name="password" value="<?php echo htmlspecialchars(@$_REQUEST['password']); ?>" size="20" /></td> </tr> <tr> <td colspan="2" align="center"> <br /> <input type="submit" name="submit" value="Login" /> </td> </tr> <tr> <td colspan="2" align="left"> <br /> <br /> <a class="your_class" href="<?php echo $GLOBALS['WEBSITE_LOGIN_REMINDER_URL'] ?>">FORGOT YOUR PASSWORD? CLICK HERE</a> <br /> <br /> <span class="your_class">If you'd like to become a dance school member</span><br /> <a class="your_class" href="http://www.your_site.com/becomeamember.php">CLICK HERE TO SIGN UP</a> </td> </tr> </table> </form> <?php endif ?> <!-- /USER LOGIN FORM -->
<!-- WELCOME MESSAGE--> <?php if (@$CURRENT_USER): ?> <span class="your_class">Welcome <?php echo $CURRENT_USER['first_name']; ?> <?php echo $CURRENT_USER['last_name']; ?>,</span> <br /> <br /> <?php endif ?> <!-- /WELCOME MESSAGE -->
<!-- VIDEO LINKS--> <?php if (@$CURRENT_USER): ?> <?php foreach ($videos_for_saleRecords as $record): ?><?php if ($CURRENT_USER['num'] == $record['videos_for_sale']): ?> <br /> <a class="your_class" href="<?php foreach ($record['video_upload'] as $upload): ?><?php echo $upload['urlPath'] ?><?php endforeach ?>">Download Your Personal<br />Training Video</a><br /> <br /><a class="your_class" href="http://www.your_site.com/videosdetail.php?<?php echo $record['num']; ?>">Watch Your Personal<br />Training Video</a> <br /> <br /> <?php endif ?> <!-- /VIDEO LINKS-->
And for the video detail page (videosdetail.php) where the student can view his or her video (using the free JWPlayer Video player described in the recipe “FREE JWPLAYER HANDLES BOTH HTML5 AND FLASH”).
In the head of the page, after the "load viewer" library call, add this "load records" call:
// load records list($videos_for_saleRecords, $videos_for_saleMetaData) = getRecords(array( 'tableName' => 'videos_for_sale', 'where' => whereRecordNumberInUrl(1), 'limit' => '1', )); $videos_for_saleRecord = @$videos_for_saleRecords[0]; // get first record
And this error message call:
<?php if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); } ?>
In the body, where you want the video to appear:
<!-- USER LOGIN FORM --> <?php if (@$errorsAndAlerts): ?> <div class="heading-text-13"><br /> <?php echo $errorsAndAlerts; ?><br /> </div> <?php endif ?>
<?php if (!@$CURRENT_USER): ?>
<form action="?" method="post"> <input type="hidden" name="action" value="login" />
<table width="400" border="0" align="center" cellpadding="2" cellspacing="0"> <tr> <td class="heading-text-13" colspan="2">You must be logged in to access this page.</td></tr><tr> <td class="body-text-bold-9">Username</td> <td><input type="text" name="username" value="<?php echo htmlspecialchars(@$_REQUEST['username']); ?>" size="20" /></td> </tr> <tr> <td class="body-text-bold-9">Password</td> <td><input type="password" name="password" value="<?php echo htmlspecialchars(@$_REQUEST['password']); ?>" size="20" /></td> </tr> <tr> <td colspan="2" align="center"> <br /> <input type="submit" name="submit" value="Login" /> </td> </tr> <tr> <td colspan="2" align="left"> <br /> <br /> <a class="special" href="<?php echo $GLOBALS['WEBSITE_LOGIN_REMINDER_URL'] ?>">FORGOT YOUR PASSWORD? CLICK HERE</a> <br /> <br /> <span class="body-text-9">If you'd like to become a dance school member</span> <a class="special" href="http://www.your_site.com/becomeamember.php">CLICK HERE TO SIGN UP</a> </td> </tr> </table> </form> <?php endif ?>
<!-- /USER LOGIN FORM -->
<!-- WELCOME MESSAGE --> <?php if (@$CURRENT_USER): ?> <table width="70%" border="0" cellspacing="10" cellpadding="5"> <tr> <td valign="top" width="75%"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td colspan="2"><?php foreach ($videos_for_saleRecords as $record): ?><?php if ($CURRENT_USER['num'] == $record['videos_for_sale']): ?> <span class="your_class">Welcome <?php echo $CURRENT_USER['first_name']; ?> <?php echo $CURRENT_USER['last_name']; ?>,</span> <br /> <span class="your_class">Enjoy your video.</span> <br /> <br /> <!-- /WELCOME MESSAGE --> </td> </tr> <tr> <td> <!-- VIDEO DOWNLOAD LINK--> <a class="your_class" href="<?php foreach ($record['video_upload'] as $upload): ?><?php echo $upload['urlPath'] ?><?php endforeach ?>">Click here if you'd prefer to download<br />your personal training video</a> <br /> <!-- /VIDEO DOWNLOAD LINK--> <?PHP endif ?> <?php endforeach ?> <br /> </td> </tr> </table> <?php endif ?> <!-- DISPLAY THE VIDEO--> <?php if (@$CURRENT_USER): ?> <?php foreach ($videos_for_saleRecords as $record): ?> <?php if ($CURRENT_USER['num'] == $record['videos_for_sale']): ?> <table align="center" width="90%" border="0" cellpadding="5"> <tr> <td> <h2 align="center"><?php echo $record['title'] ?></h2> <br /> </td> </td> <tr> <td align="center"> <div id="container"> </div> <script type="text/javascript"> jwplayer("container").setup({file: "http://www.your_site.com<?php foreach ($record['video_upload'] as $upload): ?><?php echo $upload['urlPath'] ?> <?php endforeach ?>", height: 420, width: 510, <?php if (@$record['background_image']): ?>image: "http://www.your_site.com<?php foreach ($record['background_image'] as $upload): ?><?php echo $upload['thumbUrlPath2'] ?>"<?php endforeach ?>, <?php endif ?> autostart: true, modes: [ { type: "html5" }, { type: "flash", src: "player.swf" } ]
}); </script> <!-- /DISPLAY THE VIDEO--> <!-- DISPLAY THE VIDEO DESCRIPTION--> <br /> <br /> </td> </tr> <tr> <td class="your_class" align="left"> <?php echo $record['description'] ?> </td> </tr> </table> <!-- /DISPLAY THE VIDEO DESCRIPTION--> <?php endif ?> <?php endforeach ?> <?php endif ?>
That should do it. You can style the pages any way you’d like.
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.
Terms of Service
|