| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
Copyright 2017 Buttonizer |
| 19 |
*/ |
| 20 |
namespace Buttonizer\Admin; |
| 21 |
|
| 22 |
# No script kiddies |
| 23 |
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
| 24 |
class CompanyOpened |
| 25 |
{ |
| 26 |
private $aSavedData = array() ; |
| 27 |
public function __construct() |
| 28 |
{ |
| 29 |
$this->loadData(); |
| 30 |
$this->createTable(); |
| 31 |
} |
| 32 |
|
| 33 |
private function loadData() |
| 34 |
{ |
| 35 |
$this->aSavedData = (array) get_option( 'buttonizer_opening_settings' ); |
| 36 |
} |
| 37 |
|
| 38 |
public function createTable() |
| 39 |
{ |
| 40 |
echo '<table class="opening_hours">' ; |
| 41 |
echo '<thead><td></td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td><td>Saturday</td><td>Sunday</td></thead>' ; |
| 42 |
echo '<tbody>' ; |
| 43 |
// Opened |
| 44 |
echo '<tr> |
| 45 |
<td><b>Opened from ' . (( ButtonizerLicense()->is__premium_only() ? ( !ButtonizerLicense()->is_plan( 'premium' ) ? '<span class="buttonizer-pro-feature">PRO</span>' : '' ) : '<span class="buttonizer-pro-feature">PRO</span>' )) . '</b></td> |
| 46 |
<td>' . $this->fieldOpeningTimeSelector( 'monday', false ) . '</td> |
| 47 |
<td>' . $this->fieldOpeningTimeSelector( 'tuesday', false ) . '</td> |
| 48 |
<td>' . $this->fieldOpeningTimeSelector( 'wednesday', false ) . '</td> |
| 49 |
<td>' . $this->fieldOpeningTimeSelector( 'thursday', false ) . '</td> |
| 50 |
<td>' . $this->fieldOpeningTimeSelector( 'friday', false ) . '</td> |
| 51 |
<td>' . $this->fieldOpeningTimeSelector( 'saturday', false ) . '</td> |
| 52 |
<td>' . $this->fieldOpeningTimeSelector( 'sunday', false ) . '</td> |
| 53 |
</tr>' ; |
| 54 |
// Opened |
| 55 |
echo '<tr> |
| 56 |
<td><b>Closing at ' . (( ButtonizerLicense()->is__premium_only() ? ( !ButtonizerLicense()->is_plan( 'premium' ) ? '<span class="buttonizer-pro-feature">PRO</span>' : '' ) : '<span class="buttonizer-pro-feature">PRO</span>' )) . '</b></td> |
| 57 |
<td>' . $this->fieldOpeningTimeSelector( 'monday', true ) . '</td> |
| 58 |
<td>' . $this->fieldOpeningTimeSelector( 'tuesday', true ) . '</td> |
| 59 |
<td>' . $this->fieldOpeningTimeSelector( 'wednesday', true ) . '</td> |
| 60 |
<td>' . $this->fieldOpeningTimeSelector( 'thursday', true ) . '</td> |
| 61 |
<td>' . $this->fieldOpeningTimeSelector( 'friday', true ) . '</td> |
| 62 |
<td>' . $this->fieldOpeningTimeSelector( 'saturday', true ) . '</td> |
| 63 |
<td>' . $this->fieldOpeningTimeSelector( 'sunday', true ) . '</td> |
| 64 |
</tr>' ; |
| 65 |
// Closed today |
| 66 |
echo '<tr> |
| 67 |
<td><b>Is it closed today? ' . (( ButtonizerLicense()->is__premium_only() ? ( !ButtonizerLicense()->is_plan( 'premium' ) ? '<span class="buttonizer-pro-feature">PRO</span>' : '' ) : '<span class="buttonizer-pro-feature">PRO</span>' )) . '</b></td> |
| 68 |
<td>' . $this->fieldClosedToday( 'monday' ) . '</td> |
| 69 |
<td>' . $this->fieldClosedToday( 'tuesday' ) . '</td> |
| 70 |
<td>' . $this->fieldClosedToday( 'wednesday' ) . '</td> |
| 71 |
<td>' . $this->fieldClosedToday( 'thursday' ) . '</td> |
| 72 |
<td>' . $this->fieldClosedToday( 'friday' ) . '</td> |
| 73 |
<td>' . $this->fieldClosedToday( 'saturday' ) . '</td> |
| 74 |
<td>' . $this->fieldClosedToday( 'sunday' ) . '</td> |
| 75 |
</tr>' ; |
| 76 |
echo '</tbody>' ; |
| 77 |
echo '</table>' ; |
| 78 |
echo '<div class="buttonizer-pro-text"><i class="fa fa-lock"></i> You are missing the fun! When upgrading to <a href="admin.php?page=Buttonizer-pricing">Buttonizer Pro</a> you will unlock opening hours.</div>' ; |
| 79 |
} |
| 80 |
|
| 81 |
public function fieldOpeningTimeManager( $value ) |
| 82 |
{ |
| 83 |
$sSelectBuilder = ''; |
| 84 |
// Get all 24-hours from a day |
| 85 |
for ( $i = 0 ; $i < 24 ; $i++ ) { |
| 86 |
// Set a zero before the hours less than 10 hours. (00, 01, 02 ...) |
| 87 |
if ( $i < 10 ) { |
| 88 |
$i = '0' . $i; |
| 89 |
} |
| 90 |
// Get all minutes in this hour |
| 91 |
for ( $j = 0 ; $j < 60 ; $j++ ) { |
| 92 |
// Set a zero before the minutes less than 10 minutes. (00, 01, 02 ...) |
| 93 |
if ( $j < 10 ) { |
| 94 |
$j = '0' . $j; |
| 95 |
} |
| 96 |
// Make a readable string. 00:00, 12:43, 16:16, ... |
| 97 |
$sTime = $i . ':' . $j; |
| 98 |
// Make a query |
| 99 |
$sSelectBuilder .= '<option value=\'' . $sTime . '\'' . (( $value == $sTime ? 'selected="selected"' : '' )) . '>' . $sTime . '</option>'; |
| 100 |
} |
| 101 |
} |
| 102 |
return $sSelectBuilder; |
| 103 |
} |
| 104 |
|
| 105 |
public function fieldOpeningTimeSelector( $sDay, $bIsClosedSelector = false ) |
| 106 |
{ |
| 107 |
$sName = 'buttonizer_' . $sDay . '_' . (( $bIsClosedSelector == false ? 'opened_from' : 'closing_on' )); |
| 108 |
return '<select class="buttonizer-click-to-pro" readonly><option disabled selected>' . (( $bIsClosedSelector == false ? '10:00' : '17:00' )) . '</option></select>'; |
| 109 |
} |
| 110 |
|
| 111 |
public function fieldClosedToday( $sDay = 'monday' ) |
| 112 |
{ |
| 113 |
return '<input type="checkbox" class="buttonizer-click-to-pro" readonly />'; |
| 114 |
} |
| 115 |
|
| 116 |
} |