Advertisement
Guest User

avenas8808 php coding

a guest
May 28th, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.65 KB | None | 0 0
  1. <!--This is a testing site on localhost. Domain name is fictional -->
  2. <link rel="stylesheet" href="style.css">
  3. <script src="jquery.js"></script>
  4.          
  5.           <div class="content-inner">
  6.                                               <div class="row">
  7.           <div class="column size-12">
  8.           <div class="page-header-widget page-header-info widgetbox" id="header-generic">
  9. <h2>Station Schedule</h2>
  10. </div>
  11.     </div>
  12.     </div>
  13.                               <div class="row">
  14.           <div class="column size-10">
  15.           <div class="large-schedule-widget main-col main-col-large widgetbox">
  16.                      <table class="schedule-table">
  17.                 <!-- column headers -->
  18.                 <thead>
  19.                     <tr>
  20.                         <th class="hide">Units</th>
  21.                         <th>Hours</th>
  22.                         <th>Monday</th>
  23.                         <th>Tuesday</th>
  24.                         <th class="active">Wednesday</th>
  25.                         <th>Thursday</th>
  26.                         <th>Friday</th>
  27.                         <th>Saturday</th>
  28.                         <th>Sunday</th>
  29.                     </tr>
  30.                 </thead>
  31.                 <tbody>
  32.                                    
  33.                     <tr id="units-0">
  34.                         <td class="hide">0</td>
  35.                         <!-- Every other row echo an hour block -->
  36.                         <td class="time" rowspan="2">00:00</td>
  37.                         <!-- start polling days -->
  38.                        
  39.                         <!-- finish echo a row for each of the 48 units -->
  40.                         </tr>
  41.                     <tr id="units-1">
  42.                         <td class="hide">1</td>
  43.                         <!-- Every other row echo an hour block -->
  44.                     </tr>
  45.                    
  46.                     <!-- echo a row for each of the 48 units -->
  47.                     <tr id="units-2">
  48.                         <td class="hide">2</td>
  49.                         <!-- Every other row echo an hour block -->
  50.                         <td class="time" rowspan="2">01:00</td>
  51.                         <!-- start polling days -->
  52.                        
  53.                         <!-- finish echo a row for each of the 48 units -->
  54.                 </tr>
  55.                    
  56.                     <tr id="units-3">
  57.                         <td class="hide">3</td>
  58.                         <!-- start polling days -->
  59.                         <!-- finish echo a row for each of the 48 units -->                
  60.                     </tr>
  61.                    
  62.                     <tr id="units-4">
  63.                         <td class="hide">4</td>
  64.                         <!-- Every other row echo an hour block -->
  65.                         <td class="time" rowspan="2">02:00</td>
  66.                     </tr>
  67.            
  68.                     <tr id="units-5">
  69.                         <td class="hide">5</td>
  70.                         <!-- start polling days -->
  71.                        
  72.                         <!-- finish echo a row for each of the 48 units -->
  73.                     </tr>
  74.                    
  75.                     <tr id="units-6">
  76.                         <td class="hide">6</td>
  77.                         <!-- Every other row echo an hour block -->
  78.                         <td class="time" rowspan="2">03:00</td>
  79.                         <!-- start polling days -->
  80.                         <!-- finish echo a row for each of the 48 units -->
  81.                     </tr>
  82.                    
  83.                     <tr id="units-7">
  84.                         <td class="hide">7</td>
  85.                         <!-- start polling days -->
  86.                         <!-- finish echo a row for each of the 48 units -->
  87.                     </tr>
  88.                    
  89.                     <tr id="units-8">
  90.                         <td class="hide">8</td>
  91.                         <!-- Every other row echo an hour block -->
  92.                         <td class="time" rowspan="2">04:00</td>
  93.                         <!-- start polling days -->
  94.                         <!-- finish echo a row for each of the 48 units -->
  95.                     </tr>
  96.            
  97.                     <tr id="units-9">
  98.                         <td class="hide">9</td>
  99.                         <!-- start polling days -->
  100.                         <!-- finish echo a row for each of the 48 units -->
  101.                     </tr>
  102.                    
  103.                     <tr id="units-10">
  104.                         <td class="hide">10</td>
  105.                         <!-- Every other row echo an hour block -->
  106.                         <td class="time" rowspan="2">05:00</td>
  107.                         <!-- start polling days -->
  108.                         <!-- finish echo a row for each of the 48 units -->
  109.                     </tr>
  110.                    
  111.                     <tr id="units-11">
  112.                         <td class="hide">11</td>
  113.                         <!-- start polling days -->
  114.                         <!-- finish echo a row for each of the 48 units -->
  115.                     </tr>
  116.                            
  117.                     <tr id="units-12">
  118.                         <td class="hide">12</td>
  119.                         <!-- Every other row echo an hour block -->
  120.                         <td class="time" rowspan="2">06:00</td>
  121.                         <!-- start polling days -->
  122.                         <!-- finish echo a row for each of the 48 units -->
  123.                         </tr>
  124.            
  125.                     <tr id="units-13">
  126.                         <td class="hide">13</td>
  127.                         <!-- start polling days -->
  128.                         <!-- finish echo a row for each of the 48 units -->
  129.                     </tr>
  130.                    
  131.                     <tr id="units-14">
  132.                         <td class="hide">14</td>
  133.                         <!-- Every other row echo an hour block -->
  134.                         <td class="time" rowspan="2">07:00</td>
  135.                         <!-- start polling days -->
  136.                     <!-- finish echo a row for each of the 48 units -->
  137.                     </tr>
  138.                    
  139.                     <tr id="units-15">
  140.                         <td class="hide">15</td>
  141.                         <!-- start polling days -->
  142.                         <!-- finish echo a row for each of the 48 units -->
  143.                     </tr>
  144.                    
  145.                     <tr id="units-16">
  146.                         <td class="hide">16</td>
  147.                         <!-- Every other row echo an hour block -->
  148.                         <td class="time" rowspan="2">08:00</td>
  149.                         <!-- start polling days -->
  150.                         <!-- finish echo a row for each of the 48 units -->
  151.                     </tr>
  152.                    
  153.                     <tr id="units-17">
  154.                         <td class="hide">17</td>
  155.                         <!-- start polling days -->
  156.                         <!-- finish echo a row for each of the 48 units -->
  157.                     </tr>
  158.                    
  159.                     <tr id="units-18">
  160.                         <td class="hide">18</td>
  161.                         <!-- Every other row echo an hour block -->
  162.                         <td class="time" rowspan="2">09:00</td>
  163.                         <!-- start polling days -->
  164.                         <!-- finish echo a row for each of the 48 units -->
  165.                         </tr>
  166.            
  167.                     <tr id="units-19">
  168.                         <td class="hide">19</td>
  169.                         <!-- start polling days -->
  170.                         <!-- finish echo a row for each of the 48 units -->
  171.                     </tr>
  172.                    
  173.                     <tr id="units-20">
  174.                         <td class="hide">20</td>
  175.                         <!-- Every other row echo an hour block -->
  176.                         <td class="time" rowspan="2">10:00</td>
  177.                         <!-- start polling days -->
  178.                         <!-- finish echo a row for each of the 48 units -->
  179.                     </tr>
  180.                    
  181.                     <tr id="units-21">
  182.                         <td class="hide">21</td>
  183.                         <!-- start polling days -->
  184.                         <!-- finish echo a row for each of the 48 units -->
  185.                     </tr>
  186.                    
  187.                     <tr id="units-22">
  188.                         <td class="hide">22</td>
  189.                         <!-- Every other row echo an hour block -->
  190.                         <td class="time" rowspan="2">11:00</td>
  191.                         <!-- start polling days -->
  192.                         <!-- finish echo a row for each of the 48 units -->
  193.                     </tr>
  194.                    
  195.                     <tr id="units-23">
  196.                         <td class="hide">23</td>
  197.                         <!-- start polling days -->
  198.                         <!-- finish echo a row for each of the 48 units -->
  199.                     </tr>
  200.                    
  201.                     <tr id="units-24">
  202.                         <td class="hide">24</td>
  203.                         <!-- Every other row echo an hour block -->
  204.                         <td class="time" rowspan="2">12:00</td>
  205.                         <!-- start polling days -->
  206.                         <!-- finish echo a row for each of the 48 units -->
  207.                         </tr>
  208.                     </tr>
  209.            
  210.                     <tr id="units-25">
  211.                         <td class="hide">25</td>
  212.                         <!-- start polling days -->
  213.                         <!-- finish echo a row for each of the 48 units -->
  214.                     </tr>
  215.                    
  216.                     <tr id="units-26">
  217.                         <td class="hide">26</td>
  218.                         <!-- Every other row echo an hour block -->
  219.                         <td class="time" rowspan="2">13:00</td>
  220.                         <!-- start polling days -->
  221.                         <!-- finish echo a row for each of the 48 units -->
  222.                     </tr>
  223.                    
  224.                     <tr id="units-27">
  225.                         <td class="hide">27</td>
  226.                         <!-- start polling days -->
  227.                         <!-- finish echo a row for each of the 48 units -->
  228.                     </tr>
  229.                    
  230.                     <tr id="units-28">
  231.                         <td class="hide">28</td>
  232.                         <!-- Every other row echo an hour block -->
  233.                         <td class="time" rowspan="2">14:00</td>
  234.                         <!-- start polling days -->
  235.                         <!-- finish echo a row for each of the 48 units -->
  236.                     </tr>
  237.                    
  238.                     <tr id="units-29">
  239.                         <td class="hide">29</td>
  240.                         <!-- start polling days -->
  241.                         <!-- finish echo a row for each of the 48 units -->
  242.                     </tr>
  243.                    
  244.                     <tr id="units-30">
  245.                         <td class="hide">30</td>
  246.                         <!-- Every other row echo an hour block -->
  247.                         <td class="time" rowspan="2">15:00</td>
  248.                         <!-- start polling days -->
  249.                         <!-- finish echo a row for each of the 48 units -->
  250.                 </tr>
  251.                    
  252.                     <tr id="units-31">
  253.                         <td class="hide">31</td>
  254.                         <!-- start polling days -->
  255.                         <!-- finish echo a row for each of the 48 units -->
  256.                     </tr>
  257.                    
  258.                     <tr id="units-32">
  259.                         <td class="hide">32</td>
  260.                         <!-- Every other row echo an hour block -->
  261.                         <td class="time current_time" rowspan="2">16:00</td>
  262.                         <!-- start polling days -->
  263.                         <!-- finish echo a row for each of the 48 units -->
  264.                     </tr>
  265.                    
  266.                     <tr id="units-33">
  267.                         <td class="hide">33</td>
  268.                         <!-- start polling days -->
  269.                         <!-- finish echo a row for each of the 48 units -->
  270.                     </tr>
  271.                    
  272.                     <tr id="units-34">
  273.                         <td class="hide">34</td>
  274.                         <!-- Every other row echo an hour block -->
  275.                         <td class="time" rowspan="2">17:00</td>
  276.                         <!-- start polling days -->
  277.                         <!-- finish echo a row for each of the 48 units -->
  278.                     </tr>
  279.                    
  280.                     <tr id="units-35">
  281.                         <td class="hide">35</td>
  282.                         <!-- start polling days -->
  283.                         <!-- finish echo a row for each of the 48 units -->
  284.                     </tr>
  285.                    
  286.                     <tr id="units-36">
  287.                         <td class="hide">36</td>
  288.                         <!-- Every other row echo an hour block -->
  289.                         <td class="time" rowspan="2">18:00</td>
  290.                         <!-- start polling days -->
  291.                         <!-- finish echo a row for each of the 48 units -->
  292.                     </tr>
  293.                    
  294.                     <tr id="units-37">
  295.                         <td class="hide">37</td>
  296.                         <!-- start polling days -->
  297.                         <!-- finish echo a row for each of the 48 units -->
  298.                     </tr>
  299.                    
  300.                     <tr id="units-38">
  301.                         <td class="hide">38</td>
  302.                         <!-- Every other row echo an hour block -->
  303.                         <td class="time" rowspan="2">19:00</td>
  304.                         <!-- start polling days -->
  305.                         <!-- finish echo a row for each of the 48 units -->
  306.                     </tr>
  307.                    
  308.                     <tr id="units-39">
  309.                         <td class="hide">39</td>
  310.                         <!-- start polling days -->
  311.                         <!-- finish echo a row for each of the 48 units -->
  312.                     </tr>
  313.                    
  314.                     <tr id="units-40">
  315.                         <td class="hide">40</td>
  316.                         <!-- Every other row echo an hour block -->
  317.                         <td class="time" rowspan="2">20:00</td>
  318.                         <!-- start polling days -->
  319.                         <!-- finish echo a row for each of the 48 units -->
  320.                     </tr>
  321.                    
  322.                     <tr id="units-41">
  323.                         <td class="hide">41</td>
  324.                         <!-- start polling days -->
  325.                         <!-- finish echo a row for each of the 48 units -->
  326.                     </tr>
  327.                    
  328.                     <tr id="units-42">
  329.                         <td class="hide">42</td>
  330.                         <!-- Every other row echo an hour block -->
  331.                         <td class="time" rowspan="2">21:00</td>
  332.                         <!-- start polling days -->
  333.                         <!-- finish echo a row for each of the 48 units -->
  334.                     </tr>
  335.                    
  336.                     <tr id="units-43">
  337.                         <td class="hide">43</td>
  338.                         <!-- start polling days -->
  339.                         <!-- finish echo a row for each of the 48 units -->
  340.                     </tr>
  341.                    
  342.                     <tr id="units-44">
  343.                         <td class="hide">44</td>
  344.                         <!-- Every other row echo an hour block -->
  345.                         <td class="time" rowspan="2">22:00</td>
  346.                         <!-- start polling days -->
  347.                         <!-- finish echo a row for each of the 48 units -->
  348.                     </tr>
  349.                    
  350.                     <tr id="units-45">
  351.                         <td class="hide">45</td>
  352.                         <!-- start polling days -->
  353.                         <!-- finish echo a row for each of the 48 units -->
  354.                     </tr>
  355.                    
  356.                     <tr id="units-46">
  357.                         <td class="hide">46</td>
  358.                         <!-- Every other row echo an hour block -->
  359.                         <td class="time" rowspan="2">23:00</td>
  360.                         <!-- start polling days -->
  361.                         <!-- finish echo a row for each of the 48 units -->
  362.                     </tr>
  363.                    
  364.                     <tr id="units-47">
  365.                         <td class="hide">47</td>
  366.                         <!-- start polling days -->
  367.                         <!-- finish echo a row for each of the 48 units -->
  368.                     </tr>
  369.                    
  370.                     <tr id="units-48">
  371.                         <td class="hide">48</td>
  372.                         <!-- start polling days -->
  373.                         <!-- finish echo a row for each of the 48 units -->
  374.                     </tr>                  
  375.                    
  376.                    
  377.                 </tbody>
  378.             </table>
  379. </div> <!-- end .main-col -->
  380.     </div>
  381.     <javascript>
  382.     var doFades = true;
  383.  
  384. var LocalhostStations = {
  385.   Schedule : {}
  386. };
  387.  
  388. $(document).ready(function(){
  389.  
  390.   LocalhostStations.Schedule.days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
  391.  
  392.   LocalhostStations.Schedule.Show = function () {
  393.     _s = null;
  394.     _startDate = null;
  395.     _endDate = null;
  396.     this.days = LocalhostStations.Schedule.days;
  397.     _selector = '';
  398.    
  399.     this.setShow = function(s) {
  400.       this._s = s;
  401.      
  402.       this._startDate = new Date( parseInt(s.startminutes, 10) * 1000);
  403.       this._endDate = new Date(parseInt(s.endminutes, 10) * 1000 );
  404.      
  405.     };
  406.    
  407.     this.getEndDate = function(){
  408.       return this._endDate;
  409.     }
  410.    
  411.     this.getStartDate = function(){
  412.       return this._startDate;
  413.     }
  414.    
  415.     this._getShowDay = function (){
  416.       return this.days[this.getStartDate().getDay()];
  417.     };
  418.    
  419.     this._getShowUnitsTaken = function(){
  420.       // if it's the same day
  421.       return this._getEndUnits() - this._getStartUnits();
  422.     };
  423.    
  424.     this._getEndUnits = function(){  
  425.       if(this.getEndDate().getHours() == 0)
  426.       {
  427.         //console.log(this._s.longname  +' ends at midnight');
  428.         return 48;
  429.       }
  430.      
  431.       return this.getEndDate().getMinutes() !== 0 ? (this.getEndDate().getHours() * 2) : (this.getEndDate().getHours() * 2);
  432.     };
  433.    
  434.     this._getStartUnits = function(){
  435.       if(this.getStartDate().getHours() == 0)
  436.       {
  437.         return 0;
  438.       }
  439.      
  440.       return this.getStartDate().getMinutes() !== 0 ? (this.getStartDate().getHours() * 2) : (this.getStartDate().getHours() * 2);
  441.     };
  442.    
  443.     this.getCellPositions = function() {
  444.       return {
  445.         'start' : this.getStartDate(),
  446.         'end' : this.getEndDate(),
  447.         'colIndex' : this.getStartDate().getDay() + 2,
  448.         'startUnits' : this._getStartUnits(),
  449.         'endUnits' : this._getEndUnits(),
  450.         'unitsTaken' : this._getShowUnitsTaken()
  451.       }
  452.     };
  453.    
  454.     this.pad = function(number){
  455.       return number < 10 ? '0'+number : number;
  456.     };
  457.    
  458.     // return the table cell html.
  459.     this.toHtml = function () {
  460.      
  461.       var d = new Date();
  462.       var units = this._getStartUnits();
  463.          
  464.       var rowspan = this._getShowUnitsTaken();    
  465.       var desc = this._s.description;
  466.       var name = this._s.longname;
  467.      
  468.       var starttime   = this.pad(this.getStartDate().getHours()) + ':' + this.pad(this.getStartDate().getMinutes());
  469.       var endtime   = this.pad(this.getEndDate().getHours()) + ':' + this.pad(this.getEndDate().getMinutes());
  470.      
  471.       var site = this._s.websitelink;
  472.      
  473.       var cls = this.isActive() ? 'current-program' : '';
  474.      
  475.       var isToday = this.getStartDate().getDay() === d.getDay() ? 'active-program' : '';
  476.      
  477.       var html = '<td class="schedule-show ' + isToday + ' ' + cls + '" rowspan="' + rowspan + '" data-start="' + this.getStartDate() + '" data-end="' + this.getEndDate() + '">';
  478.         html += '<div>';
  479.         html += '<a href="' + site + '" title="' + desc + '">' + name + '</a>';
  480.         html += '</div>';
  481.         if(doFades)
  482.         {
  483.           html += '<div class="schedule_details clearfix" style="display:none;">';
  484.           html += '<img width="105px" height="105px" alt="' + desc + '" src="' + this._s.showimage + '">';
  485.           html += '<strong>' + name + '</strong>';
  486.           html += '<p>' + desc + '</p>';
  487.           html += '<span>' + starttime + ' - ' + endtime +'</span>';
  488.           html += '</div>';
  489.         }
  490.         html += '</td>';      
  491.      
  492.       return html;
  493.     };
  494.    
  495.     this.setTableSelector = function(sel){
  496.       this._selector = sel;
  497.     };
  498.    
  499.     // check if we should add the active class.
  500.     this.isActive = function(){
  501.       var t = new Date();
  502.      
  503.       return  t >= this.getStartDate() && t <= this.getEndDate();
  504.     };
  505.   };
  506.  
  507.   LocalhostStations.Schedule.ScheduleGen = function(){
  508.  
  509.     return {
  510.       insertShow : function(show) {
  511.         var p = show.getCellPositions();
  512.        
  513.         $('tr#units-' + p.startUnits).append(show.toHtml());
  514.       },
  515.    
  516.       init : function (stationName){
  517.         var self = this;
  518.        
  519.         // load the schedule.
  520.         $.getJSON('http://myradiostation.localhost/schedule.php?callback=?', {
  521.           name: 'North FM'
  522.         }, function(json){
  523.           // loop each show and append to our giant table.
  524.           // this is well sick.
  525.          
  526.           if(json.success === false)
  527.           {
  528.             $('.content-inner table').remove();
  529.            
  530.             $('<div>errors</div>').appendTo('.content-inner');
  531.           }
  532.           else
  533.           {
  534.             var currentDay = '';
  535.             var day = 0;
  536.             // highlight the current time..
  537.             var d = new Date();
  538.             var weekStart = new Date();
  539.  
  540.             weekStart.setDate(d.getDate()-6-(d.getDay()||7));
  541.            
  542.             $.each(json.data.schedule, function(i, broadcast){
  543.              
  544.              
  545.               var dStart = new Date( parseInt(broadcast.startminutes, 10) * 1000);
  546.               var dEnd = new Date(parseInt(broadcast.endminutes, 10) * 1000 );
  547.  
  548.          
  549.               /*// transform to a show object defined above, if the show spans 2 days we create two show objects.
  550.               // IF THE SHOW STARTS/ENDS AT MIDNIGHT, DON'T SPLIT IT.
  551.               if(dStart.getHours() !== 0 && dEnd.getHours() !== 0 && dStart.getDate() != dEnd.getDate())
  552.               {
  553.                 var showOne = new LocalhostStations.Schedule.Show();
  554.                 showOne.setShow(broadcast);
  555.                
  556.                 // set to midnight
  557.                 showOne.getEndDate().setHours(0);
  558.                 showOne.getEndDate().setMinutes(dStart.getMinutes());
  559.  
  560.  
  561.                 // append first half of show.
  562.                 self.insertShow(showOne);
  563.                
  564.                 // handle second half.
  565.                 var showTwo = new LocalhostStations.Schedule.Show();
  566.                 showTwo.setShow(broadcast);
  567.                
  568.                 showTwo.getStartDate().setDate(showTwo.getStartDate().getDate() + 1);
  569.                 showTwo.getStartDate().setHours(0);
  570.                 showTwo.getStartDate().setMinutes(dEnd.getMinutes());
  571.                
  572.                 //console.log('2nd Half Start: ' + showTwo.getStartDate());
  573.                 //console.log('2nd Half End: ' + showTwo.getEndDate());
  574.                
  575.                 self.insertShow(showTwo);
  576.                
  577.                
  578.               }
  579.               else
  580.               {*/
  581.                 var show = new LocalhostStations.Schedule.Show();
  582.                
  583.                 show.setShow(broadcast);
  584.                 show.setTableSelector('table#schedule');
  585.  
  586.                 // add the show to the table. Thankfully the order these come out the API means they get added
  587.                 // in the right place. So don't change the schedule builder code!
  588.                
  589.                 self.insertShow(show);
  590.               //}
  591.      
  592.              
  593.             });
  594.            
  595.             var days = LocalhostStations.Schedule.days;  
  596.            
  597.             // apply the current day / time classes
  598.             $('th:contains('+ days[d.getDay()]+')').addClass('active');
  599.            
  600.             $('td.time').each(function(i, cell){
  601.               // get the value, convert to int.
  602.               var hours = $(cell).html().split(':')[0];
  603.              
  604.               // compare the hours with now, add class if matched.
  605.               if(parseInt(hours, 10) === d.getHours())
  606.               {
  607.                 $(cell).addClass('current_time');
  608.               }
  609.             });
  610.           }
  611.          
  612.          
  613.           if(doFades)
  614.           {
  615.             // apply events to show info fade in / out.
  616.             $('td.schedule-show').hover(function(){
  617.               $(this).find('.schedule_details').fadeIn('fast');
  618.             }, function(){
  619.               $(this).find('.schedule_details').fadeOut('fast');
  620.             });
  621.           }
  622.         });
  623.        
  624.        
  625.       }
  626.     };
  627.   }();
  628.  
  629.  
  630.   LocalhostStations.Schedule.ScheduleGen.init(twittiName);
  631.  
  632. });
  633. </javascript>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement