530 lines
20 KiB
PHP
530 lines
20 KiB
PHP
<?php
|
|
|
|
use App\Models\Menulocations;
|
|
use App\Models\News;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Http\Response;
|
|
|
|
class MPCMS
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
$this->initDB();
|
|
}
|
|
|
|
public static function showCount($table)
|
|
{
|
|
$count = DB::table($table)->where('status', '!=', -1)->count();
|
|
return $count;
|
|
}
|
|
|
|
|
|
public static function createMenuLink($text, $URL)
|
|
{
|
|
$isActive = request()->fullUrl() == $URL;
|
|
$activeClass = $isActive ? 'active' : '';
|
|
?>
|
|
<li>
|
|
<a class="nav-link menu-link <?php echo $activeClass; ?>" href="<?php echo $URL; ?>"><i
|
|
class="ri-file-text-line "></i> <span data-key="t-landing"><?php echo $text; ?></span></a>
|
|
</li>
|
|
<?php
|
|
}
|
|
|
|
public static function getslider()
|
|
{
|
|
$Gallery = DB::table('sliders')->where('status', 1)->orderBy('display_order')->get();
|
|
return $Gallery;
|
|
}
|
|
public static function getCustomFields()
|
|
{
|
|
$Rows = DB::table('customfields')->where('status', 1)->orderBy('display_order')->get();
|
|
return $Rows;
|
|
}
|
|
public static function getGallery($gallery_id)
|
|
{
|
|
$Gallery = DB::select("select * from tbl_galleries where gallery_id='$gallery_id'")[0];
|
|
$clients = DB::select('select * from tbl_photos where galleries_id=' . $Gallery->gallery_id . ' and status=1');
|
|
return $clients;
|
|
}
|
|
public static function getGalleryByAlias($alias)
|
|
{
|
|
$alias = trim($alias, "'\""); // Remove leading/trailing quotes, if present
|
|
$gallery = DB::table("galleries")->where('alias', $alias)->first();
|
|
|
|
if (!$gallery) {
|
|
return null;
|
|
}
|
|
|
|
$photos = DB::table('photos')->where('galleries_id', $gallery->gallery_id)->where('status', 1)->get();
|
|
|
|
return $photos;
|
|
}
|
|
|
|
|
|
|
|
public static function getarticle($alias = '')
|
|
{
|
|
$t = "select * from tbl_companyarticles where status=1";
|
|
|
|
if ($alias != '') {
|
|
$t .= " and alias='$alias'";
|
|
// dd($t);
|
|
$Article = DB::select($t);
|
|
if (!$Article)
|
|
$Article = DB::select("select * from tbl_companyarticles where status=1 LIMIT 1");
|
|
$Article = $Article[0];
|
|
$Aboutus = $Article;
|
|
$q = "select * from tbl_companyarticles where parent_article=$Aboutus->article_id";
|
|
$Aboutus->children = DB::select($q);
|
|
} else {
|
|
|
|
$Aboutus = DB::select($t);
|
|
}
|
|
//dd($Aboutus);die;
|
|
return $Aboutus;
|
|
}
|
|
|
|
public static function getgalleries($alias = '', $limit = "")
|
|
{
|
|
$q = "select * from tbl_galleries ";
|
|
if ($alias != '') {
|
|
$q .= " where alias='$alias'";
|
|
$Gallerys = DB::select($q)[0];
|
|
|
|
$t = 'select * from tbl_photos where galleries_id=' . $Gallerys->gallery_id . ' and status=1 ORDER BY photo_id DESC';
|
|
if ($limit != '') {
|
|
$t .= " limit $limit";
|
|
}
|
|
$Gallerys->images = DB::select($t);
|
|
} else {
|
|
$Gallerys = DB::select($q);
|
|
foreach ($Gallerys as $Gallery) {
|
|
$t = 'select * from tbl_photos where galleries_id=' . $Gallery->gallery_id . ' and status=1 ORDER BY photo_id DESC';
|
|
if ($limit != '') {
|
|
$t .= " limit $limit";
|
|
}
|
|
$Gallery->images = DB::select($t);
|
|
}
|
|
}
|
|
// BIBHelper::pre($Gallerys);
|
|
return $Gallerys;
|
|
}
|
|
|
|
static public function showMenu($menulocation_alias)
|
|
{
|
|
$MenuItems = MPCMS::getMenuItems($menulocation_alias);
|
|
// dd($MenuItems);
|
|
|
|
?>
|
|
<ul class="menu">
|
|
<?php foreach ($MenuItems as $menuItem): ?>
|
|
<?php $menuItem->alias = str_replace("-", "_", $menuItem->alias); ?>
|
|
<li class="nav-item <?php if (!empty($menuItem->children)): ?> dropdown <?php endif; ?>" id="myDropdown">
|
|
<a class="nav-link <?php if (!empty($menuItem->children)): ?> dropdown-toggle <?php endif; ?>" <?php if (!empty($menuItem->children)): ?> data-bs-toggle="dropdown" <?php endif; ?> aria-current="page"
|
|
href="<?php if ($menuItem->type != ""): ?>
|
|
<?php echo route($menuItem->alias); ?><?php else: ?><?php echo site_url(ltrim($menuItem->ref, '/')); ?><?php endif; ?>" target="<?php echo strtolower($menuItem->target) ?>">
|
|
|
|
<?php echo $menuItem->title; ?>
|
|
</a>
|
|
<?php if (!empty($menuItem->children)): ?>
|
|
<ul class="dropdown-menu">
|
|
<?php foreach ($menuItem->children as $menu): ?>
|
|
<li> <a class="dropdown-item" href="<?php echo route($menuItem->alias . '.' . $menu->alias) ?>"
|
|
target="<?php echo strtolower($menuItem->target); ?>"> <?php echo $menu->title; ?> </a></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php
|
|
}
|
|
|
|
|
|
public static function showTopMenu($menulocation_alias)
|
|
{
|
|
$MenuItems = MPCMS::getMenuItems($menulocation_alias);
|
|
// dd($MenuItems);
|
|
|
|
?>
|
|
<ul class="menu">
|
|
<?php foreach ($MenuItems as $MenuItem): ?>
|
|
<?php $MenuItem->alias = str_replace("-", "_", $MenuItem->alias); ?>
|
|
<li <?php if ($MenuItem->alias == "quote"): ?>class="extra-menu-item menu-item-button-link" <?php endif; ?> <?php if (!empty($MenuItem->children)): ?>class="has-children" <?php endif; ?>>
|
|
<a <?php if ($MenuItem->alias == "quote"): ?> class="fh-btn btn" <?php endif; ?> <?php if (!empty($MenuItem->children)): ?>class="dropdown-toggle" <?php endif; ?>
|
|
href="<?php if ($MenuItem->type !== ""): ?><?php echo route($MenuItem->alias); ?><?php else: ?><?php echo site_url(ltrim($MenuItem->ref, '/')); ?><?php endif; ?>"
|
|
target="<?php echo strtolower($MenuItem->target); ?>">
|
|
<?php echo $MenuItem->title; ?>
|
|
</a>
|
|
<?php if (!empty($MenuItem->children)): ?>
|
|
<ul class="sub-menu">
|
|
<?php foreach ($MenuItem->children as $subMenu): ?>
|
|
<li><a href="<?php echo route($MenuItem->alias . '.' . $subMenu->alias); ?>"
|
|
target="<?php echo strtolower($MenuItem->target); ?>"><?php echo $subMenu->title; ?></a></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php
|
|
}
|
|
|
|
|
|
public static function showTopFooter($menuLocationAlias)
|
|
{
|
|
$menuItems = MPCMS::getFooMenuItems($menuLocationAlias);
|
|
// dd($menuItems);
|
|
?>
|
|
<ul class="menu">
|
|
<?php foreach ($menuItems as $menuItem): ?>
|
|
|
|
<li><a
|
|
href="<?php echo route('services.' . $menuItem->alias); ?>target =<?php $menuItem->target ?>"><?php echo $menuItem->title; ?></a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php
|
|
}
|
|
|
|
|
|
|
|
public static function getMenuItems($menulocation_alias, $parentId = 0)
|
|
{
|
|
$menulocations_id = DB::table('menulocations')
|
|
->where('alias', $menulocation_alias)
|
|
->value('menulocation_id');
|
|
// dd($menulocation_alias);
|
|
$menuItems = DB::table('menuitems')
|
|
->where('menulocations_id', $menulocations_id)
|
|
->where('parent_menu', $parentId)
|
|
->where('status', '<>', -1)
|
|
->orderBy('display_order')
|
|
->get();
|
|
// dd($menuItems);
|
|
$result = [];
|
|
foreach ($menuItems as $menuItem) {
|
|
$children = self::getMenuItems($menulocation_alias, $menuItem->menu_id);
|
|
$menuItem->children = $children;
|
|
$result[] = $menuItem;
|
|
}
|
|
// dd($result);
|
|
return $result;
|
|
}
|
|
|
|
public static function getFooMenuItems($menulocation_alias, $parentId = 0)
|
|
{
|
|
$menulocations_id = DB::table('menulocations')
|
|
->where('alias', $menulocation_alias)
|
|
->value('menulocation_id');
|
|
// dump($menulocations_id);
|
|
$menuItems = DB::table('menuitems')
|
|
->where('menulocations_id', $menulocations_id)
|
|
// ->where('parent_menu', $parentId)
|
|
->where('status', '<>', -1)
|
|
->orderBy('display_order')
|
|
->get();
|
|
// dd($menuItems);
|
|
$result = [];
|
|
foreach ($menuItems as $menuItem) {
|
|
$children = self::getMenuItems($menulocation_alias, $menuItem->menu_id);
|
|
$menuItem->children = $children;
|
|
$result[] = $menuItem;
|
|
}
|
|
// dd($result);
|
|
return $result;
|
|
}
|
|
|
|
public static function getSiteVars()
|
|
{
|
|
$siteVars = DB::table("settings")->where('status', 1)->orderby('display_order')->get();
|
|
return $siteVars[0];
|
|
}
|
|
public static function getCountries()
|
|
{
|
|
$Countries = DB::table("countries")->where('status', 1)->orderby('display_order')->get();
|
|
return $Countries;
|
|
}
|
|
|
|
public static function getCountry($alias)
|
|
{
|
|
$Countries = DB::table("countries")->where('alias', $alias)->get();
|
|
return $Countries[0];
|
|
}
|
|
public static function getDemandCountries()
|
|
{
|
|
$demandCountries1 = DB::table('jobdemands')->where('status', 1)->orderby('display_order')->pluck('countries_id');
|
|
$demandCountries2 = DB::table('paperdemands')->where('status', 1)->orderby('display_order')->pluck('countries_id');
|
|
$demandCountries = $demandCountries1->concat($demandCountries2);
|
|
// pre($demandCountries2,true);
|
|
$demandCountries = DB::table("countries")->where('status', 1)->orderby('display_order')->whereIn('country_id', $demandCountries)->get();
|
|
return $demandCountries;
|
|
}
|
|
public static function getCertificates()
|
|
{
|
|
$Certificates = DB::table("certificates")->where('status', 1)->orderby('display_order')->get();
|
|
return $Certificates;
|
|
}
|
|
public static function getCertificate($alias)
|
|
{
|
|
$Certificate = DB::table("certificates")->where('alias', $alias)->get()[0];
|
|
return $Certificate;
|
|
}
|
|
public static function getTeams()
|
|
{
|
|
$Teams = DB::table("teams")->where('status', 1)->orderby('display_order')->get();
|
|
return $Teams;
|
|
}
|
|
public static function getTeam($alias)
|
|
{
|
|
$Team = DB::table("teams")->where('alias', $alias)->get()[0];
|
|
return $Team;
|
|
}
|
|
public static function getPaperDemands($limit = 0)
|
|
{
|
|
$query = DB::table("paperdemands")->where('status', 1)->orderBy('display_order');
|
|
|
|
if ($limit > 1) {
|
|
$query->take($limit);
|
|
}
|
|
|
|
$PaperDemands = $query->get();
|
|
|
|
return $PaperDemands;
|
|
}
|
|
|
|
public static function getPaperDemand($alias)
|
|
{
|
|
$PaperDemand = DB::table("paperdemands")->where('alias', $alias)->get()[0];
|
|
return $PaperDemand;
|
|
}
|
|
public static function getJobCategories()
|
|
{
|
|
$JobCategories = DB::table("job_categories")->where('status', 1)->orderby('display_order')->get();
|
|
return $JobCategories;
|
|
}
|
|
public static function getJobCategory($alias)
|
|
{
|
|
$JobCategory = DB::table("job_categories")->where('alias', $alias)->get()[0];
|
|
return $JobCategory;
|
|
}
|
|
public static function getCompanies()
|
|
{
|
|
$Companies = DB::table("companies")->where('status', 1)->orderby('display_order')->get();
|
|
return $Companies;
|
|
}
|
|
public static function getCompany($alias)
|
|
{
|
|
$Company = DB::table("companies")->where('alias', $alias)->get()[0];
|
|
return $Company;
|
|
}
|
|
public static function showForm($formID)
|
|
{
|
|
if (is_numeric($formID)) {
|
|
$Form = DB::table("forms")->where('form_id', $formID)->first();
|
|
} else {
|
|
$Form = DB::table("forms")->where('alias', $formID)->first();
|
|
}
|
|
|
|
if (!$Form) {
|
|
// Handle the case where the form with the given ID/alias doesn't exist
|
|
return "Error: Form (ID/Alias: $formID) not found.";
|
|
}
|
|
|
|
$csrfToken = csrf_token();
|
|
|
|
if (session('success')) {
|
|
echo '<div class="alert alert-success" role="alert">';
|
|
echo session('success');
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '<form class="mt-5" action="' . route("form.submit") . '" method="POST">';
|
|
echo '<input type="hidden" name="_token" value="' . $csrfToken . '">';
|
|
echo '<input type="hidden" name="form_id" value="' . $Form->form_id . '">';
|
|
$form_fields = json_decode($Form->form_fields);
|
|
|
|
foreach ($form_fields as $field) {
|
|
$fieldAlias = strtolower($field->fieldAlias);
|
|
$fieldName = strtolower($field->fieldName);
|
|
$fieldType = $field->fieldType;
|
|
$fieldDefault = $field->fieldDefault;
|
|
$fieldCss = $field->fieldCss;
|
|
|
|
echo '<div class="mb-3 ' . $fieldCss . '">';
|
|
echo '<label for="' . $fieldAlias . '" class="form-label">' . ucfirst($fieldName) . '</label>';
|
|
|
|
// Check if the "required" class is present in $fieldCss and add the required attribute
|
|
$isRequired = strpos($fieldCss, 'required') !== false;
|
|
|
|
if ($fieldType === 'textarea') {
|
|
echo '<textarea class="form-control ' . ($isRequired ? 'required' : '') . '" id="' . $fieldAlias . '" name="' . $fieldAlias . '" ' . ($isRequired ? 'required' : '') . '>' . $fieldDefault . '</textarea>';
|
|
} else {
|
|
echo '<input type="' . $fieldType . '" class="form-control ' . ($isRequired ? 'required' : '') . '" id="' . $fieldAlias . '" name="' . $fieldAlias . '" value="' . $fieldDefault . '" ' . ($isRequired ? 'required' : '') . '>';
|
|
}
|
|
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '<button type="submit" class="btn btn-primary">Submit</button>';
|
|
echo '</form>';
|
|
}
|
|
|
|
function initDB()
|
|
{
|
|
DB::statement("CREATE TABLE IF NOT EXISTS tbl_franchises (
|
|
franchise_id INT(11) AUTO_INCREMENT PRIMARY KEY,
|
|
title text NULL,
|
|
alias text NULL,
|
|
text TEXT NULL,
|
|
thumb VARCHAR(255),
|
|
banners VARCHAR(255),
|
|
display_order INT(11) NULL,
|
|
status INT(11) DEFAULT 1,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
createdby INT(11) DEFAULT 1,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updatedby INT(11) DEFAULT 1
|
|
);");
|
|
|
|
DB::statement("CREATE TABLE IF NOT EXISTS tbl_partners (
|
|
partner_id INT(11) AUTO_INCREMENT PRIMARY KEY,
|
|
title text NULL,
|
|
alias text NULL,
|
|
text TEXT NULL,
|
|
thumb VARCHAR(255),
|
|
display_order INT(11) NULL,
|
|
status INT(11) DEFAULT 1,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
createdby INT(11) DEFAULT 1,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updatedby INT(11) DEFAULT 1
|
|
);");
|
|
|
|
DB::statement("CREATE TABLE IF NOT EXISTS tbl_services (
|
|
service_id INT(11) AUTO_INCREMENT PRIMARY KEY,
|
|
title VARCHAR(255) NULL,
|
|
alias VARCHAR(255) NULL,
|
|
sub_text TEXT NULL,
|
|
text TEXT NULL,
|
|
icon VARCHAR(255) NULL,
|
|
thumb VARCHAR(255),
|
|
display_order INT(11) NULL,
|
|
status INT(11) DEFAULT 1,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
createdby INT(11) DEFAULT 1,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updatedby INT(11) DEFAULT 1
|
|
);");
|
|
|
|
DB::statement("CREATE TABLE IF NOT EXISTS tbl_testimonials (
|
|
testimonial_id INT(11) AUTO_INCREMENT PRIMARY KEY,
|
|
title VARCHAR(255) NULL,
|
|
alias VARCHAR(255) NULL,
|
|
text TEXT NULL,
|
|
designation VARCHAR(255) NULL,
|
|
thumb VARCHAR(255),
|
|
display_order INT(11) NULL,
|
|
status INT(11) DEFAULT 1,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
createdby INT(11) DEFAULT 1,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updatedby INT(11) DEFAULT 1
|
|
);");
|
|
|
|
|
|
DB::statement("CREATE TABLE IF NOT EXISTS tbl_customfields (
|
|
customfield_id INT(11) AUTO_INCREMENT PRIMARY KEY,
|
|
customfield_for VARCHAR(250) NULL,
|
|
customfield_forref VARCHAR(250) NULL,
|
|
title VARCHAR(255) NULL,
|
|
alias VARCHAR(255) NULL,
|
|
text TEXT NULL,
|
|
fa_icon VARCHAR(255),
|
|
logo VARCHAR(255),
|
|
display_order INT(11) NULL,
|
|
status INT(11) DEFAULT 1,
|
|
remarks TEXT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
createdby INT(11) DEFAULT 1,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updatedby INT(11) DEFAULT 1
|
|
);");
|
|
|
|
if (!Schema::hasColumn('users', 'status')) {
|
|
Schema::table('users', function (Blueprint $table) {
|
|
// Add the new column to the table
|
|
$table->string('status')->nullable();
|
|
});
|
|
}
|
|
if (!Schema::hasColumn('users', 'display_order')) {
|
|
Schema::table('users', function (Blueprint $table) {
|
|
// Add the new column to the table
|
|
$table->string('display_order')->nullable();
|
|
});
|
|
}
|
|
if (!Schema::hasColumn('users', 'createdBy')) {
|
|
Schema::table('users', function (Blueprint $table) {
|
|
// Add the new column to the table
|
|
$table->integer('createdBy')->nullable();
|
|
});
|
|
}
|
|
if (!Schema::hasColumn('users', 'updatedBy')) {
|
|
Schema::table('users', function (Blueprint $table) {
|
|
// Add the new column to the table
|
|
$table->integer('updatedBy')->nullable();
|
|
});
|
|
}
|
|
if (!Schema::hasColumn('companyarticles', 'location')) {
|
|
Schema::table('companyarticles', function (Blueprint $table) {
|
|
// Add the new column to the table
|
|
$table->string('location')->nullable()->after('parent_article');
|
|
});
|
|
}
|
|
Schema::table('companyarticles', function (Blueprint $table) {
|
|
if (!Schema::hasColumn('companyarticles', 'FBenfitTitle')) {
|
|
$table->string('FBenfitTitle')->nullable()->after('text');
|
|
}
|
|
if (!Schema::hasColumn('companyarticles', 'SBenfitTitle')) {
|
|
$table->string('SBenfitTitle')->nullable()->after('text');
|
|
}
|
|
if (!Schema::hasColumn('companyarticles', 'TBenfitTitle')) {
|
|
$table->string('TBenfitTitle')->nullable()->after('text');
|
|
}
|
|
if (!Schema::hasColumn('companyarticles', 'FBenfitText')) {
|
|
$table->text('FBenfitText')->nullable()->after('text');
|
|
}
|
|
if (!Schema::hasColumn('companyarticles', 'SBenfitText')) {
|
|
$table->text('SBenfitText')->nullable()->after('text');
|
|
}
|
|
if (!Schema::hasColumn('companyarticles', 'TBenfitText')) {
|
|
$table->text('TBenfitText')->nullable()->after('text');
|
|
}
|
|
});
|
|
|
|
Schema::table('franchises', function (Blueprint $table) {
|
|
if (!Schema::hasColumn('franchises', 'for')) {
|
|
$table->text('for')->nullable()->after('franchise_id');
|
|
}
|
|
|
|
if (!Schema::hasColumn('franchises', 'link')) {
|
|
$table->string('link')->nullable()->after('banners');
|
|
}
|
|
});
|
|
Schema::table('settings', function (Blueprint $table) {
|
|
if (!Schema::hasColumn('settings', 'address')) {
|
|
$table->string('address')->nullable()->after('email');
|
|
}
|
|
});
|
|
Schema::table('services', function (Blueprint $table) {
|
|
if (!Schema::hasColumn('services', 'parent_service')) {
|
|
$table->integer('parent_service')->nullable()->after('service_id');
|
|
}
|
|
});
|
|
}
|
|
}
|