597 lines
No EOL
19 KiB
PHP
597 lines
No EOL
19 KiB
PHP
<?php
|
|
namespace App\Helper;
|
|
|
|
use App\Models\Draft;
|
|
use App\Models\Airline;
|
|
use App\Models\CMSAuthor;
|
|
use App\Models\DraftType;
|
|
use App\Models\Insurance;
|
|
use App\Models\CMSContent;
|
|
use App\Models\TravelUser;
|
|
use App\Models\FewoLodging;
|
|
use App\Models\TravelClass;
|
|
use App\Models\TravelGuide;
|
|
use App\Models\TravelPlace;
|
|
use App\Models\IQTravelItem;
|
|
use App\Models\IQTravelGroup;
|
|
use App\Models\TravelCompany;
|
|
use App\Models\TravelCountry;
|
|
use App\Models\TravelProgram;
|
|
use App\Models\TravelNationality;
|
|
use App\Models\TravelBookingFewoChannel;
|
|
|
|
class HTMLHelper
|
|
{
|
|
|
|
|
|
private static $months = [
|
|
1 => 'Januar',
|
|
2 => 'Februar',
|
|
3 => 'März',
|
|
4 => 'April',
|
|
5 => 'Mai',
|
|
6 => 'Juni',
|
|
7 => 'Juli',
|
|
8 => 'August',
|
|
9 => 'September',
|
|
10 => 'Oktober',
|
|
11 => 'November',
|
|
12 => 'Dezember',
|
|
];
|
|
|
|
private static $days = [
|
|
0 => 'Sonntag',
|
|
1 => 'Montag',
|
|
2 => 'Dienstag',
|
|
3 => 'Mittwoch',
|
|
4 => 'Donnerstag',
|
|
5 => 'Freitag',
|
|
6 => 'Samstag',
|
|
];
|
|
|
|
private static $shortDays = [
|
|
0 => 'So',
|
|
1 => 'Mo',
|
|
2 => 'Di',
|
|
3 => 'Mi',
|
|
4 => 'Do',
|
|
5 => 'Fr',
|
|
6 => 'Sa',
|
|
];
|
|
|
|
public static $de_days = [
|
|
1 => 'Montag',
|
|
2 => 'Dienstag',
|
|
3 => 'Mittwoch',
|
|
4 => 'Donnerstag',
|
|
5 => 'Freitag',
|
|
6 => 'Samstag',
|
|
7 => 'Sonntag',
|
|
|
|
];
|
|
|
|
|
|
private static $roles = [
|
|
0 => 'Kunde',
|
|
1 => 'Admin',
|
|
2 => 'SuperAdmin',
|
|
3 => 'SysAdmin',
|
|
];
|
|
|
|
|
|
private static $salutation = [
|
|
1 => 'Herr',
|
|
2 => 'Frau',
|
|
3 => 'Divers/keine Anrede',
|
|
4 => 'Firma',
|
|
|
|
];
|
|
|
|
|
|
public static function getMonth($i){
|
|
return self::$months[$i];
|
|
}
|
|
|
|
public static function getDay($i){
|
|
return self::$days[$i];
|
|
}
|
|
|
|
public static function getShortDay($i){
|
|
return self::$shortDays[$i];
|
|
}
|
|
|
|
public static function getDeDays(){
|
|
return self::$de_days;
|
|
}
|
|
public static function getDeDay($i){
|
|
return self::$de_days[$i];
|
|
}
|
|
|
|
|
|
|
|
public static function getRoleLabel($role_id = 0, $pre = "", $post = ""){
|
|
return '<span class="badge badge-pill '.self::getLable($role_id).'">'.$pre.self::$roles[$role_id].$post.'</span>';
|
|
}
|
|
|
|
public static function getLable($id){
|
|
switch ($id) {
|
|
case 0:
|
|
return 'badge-default';
|
|
break;
|
|
case 1:
|
|
return 'badge-warning';
|
|
break;
|
|
case 2:
|
|
return 'badge-primary';
|
|
break;
|
|
case 3:
|
|
return 'badge-success';
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public static function getSelectedOptions($values, $id = null, $empty = false){
|
|
$ret = "";
|
|
if($empty){
|
|
$ret .= '<option value="">'.$empty.'</option>\n';
|
|
}
|
|
foreach ($values as $key => $value){
|
|
$attr = ($key == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$key.'" '.$attr.'>'.$value.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getActiveIcon($active){
|
|
return $active ? '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
}
|
|
|
|
public static function getRolesOptions($id = 0){
|
|
$ret = "";
|
|
foreach (self::$roles as $role_id => $value){
|
|
$attr = ($role_id == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$role_id.'" '.$attr.'>'.$value.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
|
|
public static function getSalutationOptions($id){
|
|
$ret = "";
|
|
foreach (self::$salutation as $s_id => $value){
|
|
$attr = ($s_id == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$s_id.'" '.$attr.'>'.$value.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getYearSelectOptions(){
|
|
$start = date("Y", strtotime("-5 years", time()));
|
|
$end = date("Y", strtotime("+1 years", time()));
|
|
$values = range($start, $end);
|
|
$now = date("Y", time());
|
|
$ret = "";
|
|
foreach ($values as $value){
|
|
$attr = ($value == $now) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$value.'" '.$attr.'>'.$value.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getDraftTypes($setId = false){
|
|
$options = DraftType::all()->sortByDesc('id')->sortByDesc('pos');
|
|
$ret = "";
|
|
foreach ($options as $option){
|
|
$attr = ($option->id == $setId) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function createTimeRange($start = '0:00', $end = "23:30", $interval = '30 mins'){
|
|
|
|
$start_time = strtotime($start);
|
|
$end_time = strtotime($end);
|
|
$format = 'G:i';
|
|
|
|
$current = time();
|
|
$add_time = strtotime('+'.$interval, $current);
|
|
$diff = $add_time - $current;
|
|
|
|
$times = [];
|
|
while ($start_time < $end_time){
|
|
$times[] = date($format, $start_time);
|
|
$start_time += $diff;
|
|
}
|
|
$times[] = date($format, $start_time);
|
|
return $times;
|
|
}
|
|
|
|
|
|
public static function getTimeInSteps($id = false){
|
|
|
|
$times = self::createTimeRange();
|
|
$ret = '';
|
|
foreach ($times as $item){
|
|
$attr = ($item === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$item.'" '.$attr.'>'.$item.'</option>\n';
|
|
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getRangeOptions($id = false, $range = 30, $name = "", $start=1){
|
|
|
|
$range = range($start, $range);
|
|
$ret = "";
|
|
|
|
foreach ($range as $item){
|
|
$attr = ($item === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$item.'" '.$attr.'>'.$item.$name.'</option>\n';
|
|
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getDraftOptions($setId = false){
|
|
|
|
$options = Draft::where('active', 1)->orderBy('id', 'DESC')->get();
|
|
$ret = "";
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $setId) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getAuthorOptions($setId = false){
|
|
|
|
$options = CMSAuthor::orderBy('id', "DESC")->get();
|
|
$ret = "";
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $setId) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getCMSContentOptions($identifier, $setId = false, $empty=false){
|
|
$options = CMSContent::where('identifier', '=', $identifier)->get()->sortBy('pos');
|
|
$ret = "";
|
|
if($empty){
|
|
$ret = '<option value="0">Keine Vorlage</option>\n';
|
|
}
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === intval($setId)) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getTravelClassOptions($programId = false, $setId = false){
|
|
$options = TravelClass::where('program_id', $programId)->get();
|
|
$ret = '<option value="">alle Kategorien</option>\n';
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $setId) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getTravelCountriesOptions($countryId = false, $crm = true){
|
|
$checked = [];
|
|
if($countryId){
|
|
!is_array($countryId) ? $checked = array($countryId) : $checked = $countryId;
|
|
}
|
|
$options = TravelCountry::where('active_backend',1)->get();
|
|
$ret = '';
|
|
foreach ($options as $option){
|
|
$id = $crm ? $option->crm_id : $option->id;
|
|
$attr = (in_array($id, $checked)) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getTravelUserOptions($id = false, $order = "ASC", $empty=false){
|
|
$options = TravelUser::orderBy('id', $order)->get();
|
|
$ret = '';
|
|
if($empty){
|
|
$ret = '<option value="">Bitte wählen</option>\n';
|
|
}
|
|
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->first_name.' '.$option->last_name.' | '.$option->email.' ('.$option->id.')</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getTravelPlaceOptions($id = false, $order = "ASC", $empty=false){
|
|
$options = TravelPlace::where('active',1)->orderBy('id', $order)->get();
|
|
$ret = '';
|
|
if($empty){
|
|
$ret = '<option value="">Bitte wählen</option>\n';
|
|
}
|
|
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getIQTravelItemsOptions($id = false, $order = "ASC", $empty=false){
|
|
$options = IQTravelItem::where('active',1)->orderBy('id', $order)->get();
|
|
$ret = '';
|
|
if($empty){
|
|
$ret = '<option value="">Bitte wählen</option>\n';
|
|
}
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getIQTravelGroupsOptions($id = false, $order = "ASC", $empty=false){
|
|
$options = IQTravelGroup::where('active',1)->orderBy('id', $order)->get();
|
|
$ret = '';
|
|
if($empty){
|
|
$ret = '<option value="">Bitte wählen</option>\n';
|
|
}
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getCustomerMailDirsOptions(CMSContent $customer_mail_dir, $checked = []){
|
|
//$checked = [];
|
|
$model = $customer_mail_dir->getArrayContent('model');
|
|
switch ($model){
|
|
case 'TravelCountry':
|
|
$options = \App\Models\Sym\TravelCountry::where('active_backend',1)->get();
|
|
break;
|
|
case 'Airline':
|
|
$options = Airline::where('name_full', 'like', '%Xemail%')->get();
|
|
break;
|
|
case 'Insurance':
|
|
$options = Insurance::where('active',1)->get();
|
|
break;
|
|
case 'TravelCompany':
|
|
$options = TravelCompany::where('active',1)->get();
|
|
break;
|
|
default:
|
|
return '';
|
|
}
|
|
$ret = '';
|
|
foreach ($options as $option){
|
|
$attr = (in_array($option->id, $checked)) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getFewoLodgingOptions($id = false){
|
|
$options = FewoLodging::all();
|
|
$ret = '';
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
public static function getTravelBookingFewoChannelOptions($id = false){
|
|
$options = TravelBookingFewoChannel::all();
|
|
$ret = '';
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getTravelNationalityOptions($id = false){
|
|
$options = TravelNationality::where('active',1)->get();
|
|
$ret = '';
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getTravelGuideOptions($id = false){
|
|
$options = TravelGuide::where('active',1)->get();
|
|
$ret = '<option value="">keinen Inhalt</option>\n';
|
|
foreach ($options as $option){
|
|
$attr = ($option->id === $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option->id.'" '.$attr.'>'.$option->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
|
|
|
|
public static function getWeekdaysOptions($programId = false, $weekdays = []){
|
|
if($programId){
|
|
$tp = TravelProgram::findOrFail($programId);
|
|
$options = explode(',', $tp->weekdays);
|
|
}else{
|
|
$options = range(0, 6);
|
|
}
|
|
$ret = '<option value="">alle Wochentage</option>\n';
|
|
foreach ($options as $option){
|
|
$attr = (in_array($option, $weekdays)) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$option.'" '.$attr.'>'.self::getDay($option).'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getWeekdaysString($weekdays = [], $short = false){
|
|
|
|
$ret = "";
|
|
if(is_array($weekdays) && count($weekdays)){
|
|
foreach($weekdays as $weekday){
|
|
if($weekday !== NULL){
|
|
if($short){
|
|
$ret .= self::getShortDay($weekday).', ';
|
|
}else{
|
|
$ret .= self::getDay($weekday).', ';
|
|
|
|
}
|
|
}
|
|
}
|
|
if($ret != ""){
|
|
return rtrim($ret, ", ");
|
|
}
|
|
}
|
|
return "alle Wochentage";
|
|
}
|
|
|
|
public static function getParentBy($obj = NULL, $options, $empty=true){
|
|
|
|
$ret = "";
|
|
$setId = 0;
|
|
if($obj){
|
|
$setId = $obj->id;
|
|
}
|
|
if($empty){
|
|
// $ret .= '<option value="">Main (No-Parent)</option>\n';
|
|
}
|
|
foreach ($options as $id => $name){
|
|
$attr = ($id === $setId) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$id.'" '.$attr.'>'.$name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
|
|
public static function filterHTML($html, $arg = [], $save = false){
|
|
|
|
$dom = new \DOMDocument('1.0', 'UTF-8');
|
|
//@$dom->loadHTML();
|
|
|
|
@$dom->loadHTML( mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
|
|
if(isset($arg['src'])){
|
|
|
|
if(in_array('addHost', $arg['src'])){
|
|
$images = $dom->getElementsByTagName('img');
|
|
foreach ($images as $image) {
|
|
|
|
$src = $image->getAttribute('src');
|
|
if(strpos($src, 'http') === false){
|
|
$host = config('app.url_stern');
|
|
if(strpos($src, $host) === false){
|
|
$src = $host."/".ltrim($src, '/');
|
|
}
|
|
$image->setAttribute('src', $src);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(in_array('removeHost', $arg['src'])){
|
|
$images = $dom->getElementsByTagName('img');
|
|
foreach ($images as $image) {
|
|
$src = $image->getAttribute('src');
|
|
$host = config('app.url_stern');
|
|
if(strpos($src, $host) !== false){
|
|
$src = str_replace($host, '', $src);
|
|
}
|
|
$image->setAttribute('src', $src);
|
|
}
|
|
}
|
|
}
|
|
$html = $dom->saveHTML();
|
|
|
|
$html = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', $html);
|
|
|
|
if($save){
|
|
return mb_convert_encoding($html, "UTF-8", "HTML-ENTITIES");
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
|
|
/*
|
|
public static function getIndustrySectorsWithoutParents($id = false, $sameId = false, $all = true){
|
|
$values = IndustrySector::where('parent_id', null)->get();
|
|
$ret = "";
|
|
if($all){
|
|
$ret .= '<option value="">'.__('no').'</option>\n';
|
|
}
|
|
foreach ($values as $value){
|
|
if($sameId == $value->id){
|
|
continue;
|
|
}
|
|
$attr = ($value->id == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getContriesWithMore($id, $all=true){#
|
|
$values = Country::all();
|
|
$counter = 1;
|
|
$ret = "";
|
|
if($all){
|
|
$ret .= '<option value="">'.__('please select').'</option>\n';
|
|
|
|
}
|
|
foreach ($values as $value){
|
|
if( $counter == 7){
|
|
$ret .= '<optgroup label="'.__('further countrie').'">';
|
|
}
|
|
$attr = ($value->id == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->getLocated().'</option>\n';
|
|
|
|
$counter ++;
|
|
}
|
|
$ret .= '</optgroup>';
|
|
return $ret;
|
|
}
|
|
|
|
public static function getContriesCodes($id, $all=true){#
|
|
$values = Country::all();
|
|
$counter = 1;
|
|
$ret = "";
|
|
if($all){
|
|
$ret .= '<option value="">'.__('please select').'</option>\n';
|
|
|
|
}
|
|
foreach ($values as $value){
|
|
|
|
if(!$value->phone) continue;
|
|
if( $counter == 7){
|
|
$ret .= '<optgroup label="'.__('further countrie').'">';
|
|
}
|
|
$attr = ($value->id == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->phone.'('.$value->getLocated().')</option>\n';
|
|
|
|
$counter ++;
|
|
}
|
|
$ret .= '</optgroup>';
|
|
return $ret;
|
|
}
|
|
|
|
|
|
public static function getSalutation($id){
|
|
$values = array('mr' => __('MR'), 'ms' => __('MS'));
|
|
$ret = "";
|
|
$ret .= '<option value="">'.__('please select').'</option>\n';
|
|
foreach ($values as $key => $value){
|
|
$attr = ($key == $id) ? 'selected="selected"' : '';
|
|
$ret .= '<option value="'.$key.'" '.$attr.'>'.$value.'</option>\n';
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public static function getSalutationLang($id){
|
|
$values = array('mr' => __('MR'), 'ms' => __('MS'));
|
|
return (!empty($values[$id]) ? $values[$id] : '');
|
|
}
|
|
*/
|
|
} |