Guest User

PHP stament

a guest
Aug 26th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.96 KB | None | 0 0
  1. <?php include 'includes/db.conn.php';
  2.       include 'includes/functions.php';
  3.  ?>
  4.  
  5. <?php
  6.  
  7.     //callback URL
  8.     $url = "http://www.SwingAcademy.com/web/external/api.ashx?method=getLessons&callback=?";  
  9.  
  10.     //your Group ID    
  11.     $groupID = "43AB3367-F58D-487E-B2C6-2571A3A3508C";
  12.  
  13.     //custom variables, will change in live site
  14.     $num_results = "";
  15.     $instructor_id = "3788";
  16.     $owner_id = "3788";
  17.     $lesson_group_id = "6";
  18.  
  19.     //post varaibles in an array back to API to receive response   
  20.     $post_data = array (
  21.             "NUMRESULTS" => $num_results,
  22.             "GROUPID" => $groupID,
  23.             "OWNERID" => $owner_id,
  24.             "INSTRUCTORID" => $instructor_id
  25.             );  
  26.            
  27.            
  28. //////////////////////////////////////         
  29. //////////////////////////////////////
  30. //do not edit below this line/////////
  31. //////////////////////////////////////
  32. //////////////////////////////////////
  33.  
  34.  
  35.     $curl_options = array(
  36.     CURLOPT_URL => $url ,
  37.     CURLOPT_POST => true,
  38.     CURLOPT_POSTFIELDS => http_build_query( $post_data ),
  39.     CURLOPT_HTTP_VERSION => 1.0,
  40.     CURLOPT_RETURNTRANSFER => true,
  41.     CURLOPT_HEADER => false
  42.     );
  43.  
  44.     $curl = curl_init();
  45.  
  46.     curl_setopt_array( $curl, $curl_options );
  47.  
  48.     $result = curl_exec( $curl );
  49.    
  50.     //un comment to show returned data in JSONP format, we need to convert it to JSON
  51.     //for PHP to like it.
  52.    
  53.     //echo $result;
  54.  
  55.     //convert JSONP to JSON here
  56.     function jsonp_decode($jsonp, $assoc = false) { // PHP 5.3 adds depth as third parameter to json_decode
  57.     if($jsonp[0] !== '[' && $jsonp[0] !== '{') { // we have JSONP
  58.        $jsonp = substr($jsonp, strpos($jsonp, '('));
  59.     }
  60.     return json_decode(trim($jsonp,'();'), $assoc);
  61.     }
  62.  
  63.     //check JSON for any errors
  64.     switch (json_last_error()) {
  65.         case JSON_ERROR_NONE:
  66.             echo ' - No errors';
  67.         break;
  68.         case JSON_ERROR_DEPTH:
  69.             echo ' - Maximum stack depth exceeded';
  70.         break;
  71.         case JSON_ERROR_STATE_MISMATCH:
  72.             echo ' - Underflow or the modes mismatch';
  73.         break;
  74.         case JSON_ERROR_CTRL_CHAR:
  75.             echo ' - Unexpected control character found';
  76.         break;
  77.         case JSON_ERROR_SYNTAX:
  78.             echo ' - Syntax error, malformed JSON';
  79.         break;
  80.         case JSON_ERROR_UTF8:
  81.             echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
  82.         break;
  83.         default:
  84.             echo ' - Unknown error';
  85.         break;
  86.     }
  87.    
  88.     //uncomment this to show errors in JSON
  89.    
  90.     //echo PHP_EOL;
  91.    
  92.        
  93.     //echo JSON data
  94.     //echo "<pre>";
  95.     //var_dump(jsonp_decode($result, true));
  96.     //echo "</pre>";
  97.  
  98.     //assign JSON data
  99.     $arrResult = jsonp_decode($result, true);?>
  100.    
  101. <div class="row">
  102. <div class="span2">......</div>
  103. <div class="span7">
  104.     <h1 class="red-font">Your Prior Reviews</h1>
  105.  
  106.  
  107.  
  108. <?
  109. /////////////////////////////////////////////////
  110. //////////////////// do not edit above this line/
  111. /////////////////////////////////////////////////
  112. /////////////////////////////////////////////////
  113.  
  114.  
  115.    
  116.     //query our DB for instructor information
  117.     $query_in ="SELECT instructor_email, first_name, last_name, user_id, rst_level FROM swing_instructors WHERE user_id=?";
  118.     if ($stmt1 = $mysqli->prepare($query_in)) {
  119.         $stmt1->bind_param("i", $instructor_id);
  120.        
  121.     $stmt1->execute(); 
  122.     /* bind result variables */
  123.     $stmt1->bind_result($instructor_email, $first_name, $last_name, $instructor_id, $rst_level);
  124.     /* fetch values */
  125.     while ($stmt1->fetch()) {
  126.         $instructor_email;
  127.         $first_name;
  128.         $last_name;
  129.         $instructor_id;
  130.         $rst_level;
  131.     }
  132.     }
  133.    
  134.     //query our DB for lesson information, correlate with info from API calls
  135.     $query ="SELECT instructor_id, lesson_comments, user_id, lesson_date, video_ids, lesson_id FROM swing_viewer_lessons WHERE instructor_id=? and user_id=?";
  136.     if ($stmt = $mysqli->prepare($query)) {
  137.         $stmt->bind_param("ii", $instructor_id, $owner_id);
  138.        
  139.     $stmt->execute();  
  140.     /* bind result variables */
  141.     $stmt->bind_result($instructor_id, $lesson_comments, $owner_id, $lesson_date, $video_ids, $lesson_id);
  142.     /* fetch values */
  143.     while ($stmt->fetch()) {
  144.        
  145.     //convert video id array to single lines
  146.     $pieces = explode(",", $video_ids);
  147.     //$pieces[0]; // piece1
  148.     //$pieces[1]; // piece2
  149.     //$pieces[2]; // piece3
  150.    
  151.        
  152.        
  153.     //iterate through API information
  154.     foreach($arrResult['VIDEOS'] as $p){
  155.    
  156.     //convert epoch to date Y-M-D format
  157.     $epoch = $p['LESSONDATE'] ;
  158.     $dt = new DateTime("@$epoch"); // convert UNIX timestamp to PHP DateTime
  159.    
  160.     //check to make sure both lesson IDs match from API and our DB
  161.     if($lesson_id == $p['LESSONID']){?>
  162.    
  163.     <div class="lessonHolder">
  164.         <p style="font-size: 16px;"><strong>Instructor Title</strong></p>
  165.      <p><?php echo $dt->format('m/d/y g:ia'); // output = 2013-08-15 ?>
  166.         <?php echo $first_name;?>
  167.         <?php echo $last_name;?>,
  168.         <?php echo $rst_level;?>
  169.        
  170.     </p>
  171.     <?php //echo $instructor_email;?>
  172.    
  173.     <div class="span3">
  174.     <?php
  175.     if($p['THUMBNAIL'] == NULL){
  176.     echo "<a href=\"#myModal_".$lesson_id."\" data-toggle=\"modal\"><img src=\"http://placehold.it/250x150\"/></a>";
  177.     }
  178.     else
  179.     {
  180.     echo "<a href=\"#myModal_".$lesson_id."\" role=\"button\" class=\"btn\"  data-toggle=\"modal\"><img src=".$p['THUMBNAIL']."/></a>";
  181.     }?>
  182.     <a href="lessons.php?lessonID=<?php echo $lesson_id ;?>" style="margin-top: 10px;width:210px;" class="btn btn-success btn-large">Click to Watch Review</a>
  183.     </div>
  184.     <div class="span3">
  185.     <h3>Your Lesson Notes</h3>
  186.     <?php if($p['NOTES'] == NULL){
  187.         echo "You did not include any notes with the lesson request.<br/><br/>";
  188.     }else{
  189.         echo $p['NOTES'];
  190.     }
  191.     ?>
  192.        
  193.     <h3>Recommended Videos:</h3>
  194.    
  195.     <?php
  196.     //iterate through video IDS in our DB
  197.     foreach ($pieces as $key) {
  198.         echo $key; 
  199.    
  200.     $query4 ="SELECT id, video_name, link, phase FROM videos WHERE id=$key";
  201.     if ($stmt4 = $mysqli->prepare($query4)) {
  202.     $stmt4->execute(); 
  203.     /* bind result variables */
  204.     $stmt4->bind_result($id, $vid_name, $vid_link, $phase);
  205.     /* fetch values */
  206.     while ($stmt4->fetch()) {
  207.     echo "<input type='checkbox' name='checkbox[]' id='$id'  value='$id' />";
  208.     echo "<a href='http://www.rotaryswing.com/golf-instruction/video/rst-index.php?cat=$phase&subcat=Rotary%20Swing%20Tour&video=$id&id=$vid_link&name=$vid_name' target=\"blank\">" .$vid_name. "</a><br>";
  209.     }
  210. }
  211. }
  212.     ?>
  213.    
  214.    
  215.  
  216.     <?php echo $lesson_id . "<br/>";?>
  217.    
  218.     <!-- Modal -->
  219. <div id="myModal_<?php echo $lesson_id;?>" style="display: none;" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  220. <div class="modal-header">
  221. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  222. <h3 id="myModalLabel">Modal header</h3>
  223. </div>
  224. <div class="modal-body">
  225. <p> <iframe src="<?php echo $p['VIDEOURL'];?>" width="800px" height="470px"></iframe>
  226. </p>
  227. </div>
  228. <div class="modal-footer">
  229. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  230. </div>
  231. </div>
  232.    
  233.     </div>
  234.     </div>
  235.  
  236.     <?php }}}} ?>
  237.     </div>
Advertisement
Add Comment
Please, Sign In to add comment