351 lines
13 KiB
PHP
Executable File
351 lines
13 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models;
|
|
use Session;
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
|
class NetworkOperatorsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function indexBAK()
|
|
{
|
|
$network_operators = new Models\NetworkOps;
|
|
$table_columns = \DB::select(\DB::raw("show full columns from network_operators"));
|
|
$exclude_arr = [
|
|
'updated_at', 'id', 'account_manager_id', 'created_at'
|
|
];
|
|
$columns = [];
|
|
$queries = [];
|
|
foreach ($table_columns as $key) {
|
|
$columns[$key->Field] = $key->Field;
|
|
}
|
|
foreach ($columns as $col) {
|
|
if (request('filter') == $col) {
|
|
$filter = request('filter');
|
|
$keyword = request('keyword');
|
|
$table_arr = ['staff_id'];
|
|
if (in_array($col, $table_arr)) {
|
|
$key = $this->get_filter_ids($filter, $keyword);
|
|
if (!empty($key)) {
|
|
$keyword = $key;
|
|
}
|
|
}
|
|
$network_operators = $network_operators->where($col, 'like', '%'.$keyword.'%');
|
|
$queries[$col] = request('keyword');
|
|
}
|
|
}
|
|
|
|
$network_operators = $network_operators->with('account_manager_info', 'country_info')->orderBy('created_at', 'DESC')->paginate(40)->appends($queries);
|
|
$data = [
|
|
'page_title' => 'Network Operators',
|
|
'columns' => Arr::except($columns, $exclude_arr),
|
|
'network_operators' => $network_operators
|
|
];
|
|
|
|
return view('network_ops.index', $data);
|
|
}
|
|
public function index(){
|
|
//$mno_arr = Models\NetworkOps::get();
|
|
$data = [
|
|
'page_title' => 'Mobile Network Operators',
|
|
'current_user' => session('current_user')
|
|
];
|
|
return view('network_ops.index', $data);
|
|
}
|
|
public function getMnosJson(Request $request)
|
|
{
|
|
//$this->log_query();
|
|
$mno_arr = \DB::table('network_operators')
|
|
->join('staff_members AS staffam', 'staffam.id', '=', 'network_operators.account_manager_id')
|
|
->join('staff_members AS staffmodify', 'staffmodify.id', '=', 'network_operators.last_modified_by')
|
|
->select('network_operators.id', 'staffam.name AS accountManager', 'network_operators.name AS networkName', 'network_operators.country', 'network_operators.connection_status', 'staffmodify.name AS modifiedBy')
|
|
->orderBy('network_operators.name', 'ASC')
|
|
->paginate(15);
|
|
|
|
if($request->has('keyword')){
|
|
$keyword = $request->keyword;
|
|
$mno_arr = \DB::table('network_operators')
|
|
->join('staff_members AS staffam', 'staffam.id', '=', 'network_operators.account_manager_id')
|
|
->join('staff_members AS staffmodify', 'staffmodify.id', '=', 'network_operators.last_modified_by')
|
|
->select('network_operators.id', 'staffam.name AS accountManager', 'network_operators.name AS networkName', 'network_operators.country', 'network_operators.connection_status', 'staffmodify.name AS modifiedBy')
|
|
->whereRaw("network_operators.name LIKE '%$keyword%' OR network_operators.connection_status LIKE '%$keyword%' OR network_operators.country LIKE '%$keyword%' OR staffam.name LIKE '%$keyword%' ")
|
|
->orderBy('network_operators.name', 'ASC')
|
|
->paginate(15);
|
|
}
|
|
return response()->json($mno_arr);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$countries = Models\Country::pluck('en_short_name','en_short_name');
|
|
$account_manager = Models\SystemUser::pluck('name', 'id');
|
|
$services = Models\Service::pluck('name', 'name');
|
|
$status = ['Active' => 'Active', 'Inactive' => 'Inactive', 'Pending' => 'Pending'];
|
|
$data = [
|
|
'page_title' => 'Create Network Operator',
|
|
'countries'=> $countries,
|
|
'account_manager' => $account_manager,
|
|
'services' => $services,
|
|
'status' => $status
|
|
];
|
|
|
|
return view('network_ops.create', $data);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required',
|
|
'country' => 'required',
|
|
'account_manager_id' => 'required',
|
|
'services' => 'required',
|
|
'contact_person' => 'required',
|
|
'email' => 'required',
|
|
'phone' => 'required'
|
|
]);
|
|
|
|
$operator_arr = [
|
|
'name' => $request->name,
|
|
'country' => $request->country,
|
|
'account_manager_id' => $request->account_manager_id,
|
|
'contact_person' => $request->contact_person,
|
|
'connection_status' => $request->status,
|
|
'contact_person_phone' => $request->phone,
|
|
'contact_person_email' => $request->email,
|
|
'last_modified_by' => session('current_user.id')
|
|
];
|
|
if ($request->has('services')) {
|
|
$operator_arr['services'] = json_encode($request->services);
|
|
}
|
|
if ($request->has('phone')) {
|
|
$operator_arr['phone'] = $request->phone;
|
|
}
|
|
if ($request->has('skype_name')) {
|
|
$operator_arr['contact_person_skype'] = $request->skype_name;
|
|
}
|
|
if ($request->has('linkedin_name')) {
|
|
$operator_arr['linkedin_name'] = $request->linkedin_name;
|
|
}
|
|
if ($request->has('contact_person')) {
|
|
$operator_arr['contact_person'] = $request->contact_person;
|
|
}
|
|
|
|
$saved = Models\NetworkOps::create($operator_arr);
|
|
Session::flash('success_message', 'Network Operator successfully added');
|
|
return redirect(url('mnos'));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$operator_arr = Models\NetworkOps::find($id);
|
|
$data = [
|
|
'page_title' => 'Network Operator Show',
|
|
'operator_arr' => $operator_arr
|
|
];
|
|
|
|
return view('network_ops.show', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$network_arr = Models\NetworkOps::findOrFail($id);
|
|
$countries = Models\Country::pluck('en_short_name','en_short_name');
|
|
$account_manager = Models\SystemUser::pluck('name', 'id');
|
|
$services = Models\Service::pluck('name', 'name');
|
|
$connection_types = ['VPN' => 'VPN', 'DIRECT' => 'DIRECT'];
|
|
$ip_addresses = Models\Mnoips::where('mno_id', $id)->get();
|
|
if ($network_arr->support_emails) {
|
|
$support_emails = json_decode($network_arr->support_emails, true);
|
|
$support_emails = array_combine($support_emails, $support_emails);
|
|
$old_support_emails = json_decode($network_arr->support_emails, true);
|
|
}
|
|
else{
|
|
$support_emails = [];
|
|
$old_support_emails = [];
|
|
}
|
|
if ($network_arr->support_phones) {
|
|
$support_phones = json_decode($network_arr->support_phones, true);
|
|
$support_phones = array_combine($support_phones, $support_phones);
|
|
$old_support_phones = json_decode($network_arr->support_phones, true);
|
|
}
|
|
else{
|
|
$support_phones = [];
|
|
$old_support_phones = [];
|
|
}
|
|
|
|
if ($network_arr->support_skype) {
|
|
$support_skype_arr = json_decode($network_arr->support_skype, true);
|
|
$support_skype_arr = array_combine($support_skype_arr, $support_skype_arr);
|
|
$old_support_skype_arr = json_decode($network_arr->support_skype, true);
|
|
}
|
|
else{
|
|
$support_skype_arr = [];
|
|
$old_support_skype_arr = [];
|
|
}
|
|
$old_connection_type = [];
|
|
if ($network_arr->connection_type) {
|
|
$connection_type = json_decode($network_arr->connection_type, true);
|
|
$connection_type = array_combine($connection_type, $connection_type);
|
|
$old_connection_type = json_decode($network_arr->connection_type, true);
|
|
}
|
|
else{
|
|
$old_connection_type = [];
|
|
}
|
|
|
|
if ($network_arr->connection_status == 'Active') {
|
|
$status_bg = "info";
|
|
}
|
|
elseif ($network_arr->connection_status == 'Pending') {
|
|
$status_bg = "warning";
|
|
}
|
|
else{
|
|
$status_bg = "danger";
|
|
}
|
|
$data = [
|
|
'page_title' => 'Edit Network Operator',
|
|
'network_arr' => $network_arr,
|
|
'countries'=> $countries,
|
|
'account_manager' => $account_manager,
|
|
'current_services' => json_decode($network_arr->services, true),
|
|
'services' => $services->toArray(),
|
|
'support_emails' => $support_emails,
|
|
'support_skype_arr' => $support_skype_arr,
|
|
'support_phones' => $support_phones,
|
|
'old_support_emails' => $old_support_emails,
|
|
'old_support_skype_arr' => $old_support_skype_arr,
|
|
'old_support_phones' => $old_support_phones,
|
|
'status_bg' => $status_bg,
|
|
'connection_types' => $connection_types,
|
|
'old_connection_type' => $old_connection_type,
|
|
'ip_addresses' => $ip_addresses
|
|
];
|
|
return view('network_ops.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$request->validate([
|
|
'name' => 'required',
|
|
'country' => 'required',
|
|
'account_manager_id' => 'required',
|
|
'services' => 'required',
|
|
'contact_person' => 'required',
|
|
'contact_person_email' => 'required',
|
|
'contact_person_phone' => 'required'
|
|
]);
|
|
|
|
// dd($request->all());
|
|
$operator_update = Models\NetworkOps::find($id);
|
|
$operator_update->name = $request->name;
|
|
$operator_update->country = $request->country;
|
|
$operator_update->account_manager_id = $request->account_manager_id;
|
|
|
|
|
|
$operator_update->contact_person_email = $request->contact_person_email;
|
|
$operator_update->contact_person_phone = $request->contact_person_phone;
|
|
$operator_update->contact_person = $request->contact_person;
|
|
$operator_update->connection_status = $request->connection_status ?? "";
|
|
$operator_update->connection_type = ($request->connection_type) ? json_encode($request->connection_type) : "";
|
|
|
|
$operator_update->contact_person_skype = $request->contact_person_skype ?? "";
|
|
|
|
#$operator_update->connections = ($request->connections) ? json_encode($request->connections) : "";
|
|
$operator_update->services = ($request->services) ? json_encode($request->services) : "";
|
|
$operator_update->support_emails = ($request->support_emails) ? json_encode($request->support_emails) : "";
|
|
$operator_update->support_phones = ($request->support_phones) ? json_encode($request->support_phones) : "";
|
|
$operator_update->support_skype = ($request->support_skype) ? json_encode($request->support_skype) : "";
|
|
|
|
|
|
$result = $operator_update->save();
|
|
|
|
Session::flash('success_message', 'Network Operator successfully Updated');
|
|
return redirect(url('mnos'));
|
|
}
|
|
public function ipStore(Request $request)
|
|
{
|
|
$request->validate([
|
|
'mno_id' => 'required',
|
|
'ip_address' => 'required|ipv4',
|
|
'service' => 'required',
|
|
'port' => 'sometimes|numeric',
|
|
'status' => 'required'
|
|
]);
|
|
$auth_user = session('current_user');
|
|
|
|
$addresses_arr = [
|
|
'ip_address' => $request->ip_address,
|
|
'mno_id' => $request->mno_id,
|
|
'service' => $request->service,
|
|
'port' => $request->port,
|
|
'status' => $request->status,
|
|
'created_by' => $auth_user['id'],
|
|
'last_modified_by' => $auth_user['id']
|
|
];
|
|
|
|
|
|
$result = Models\Mnoips::create($addresses_arr);
|
|
|
|
if ($result) {
|
|
$data = ['code' => 1, 'msg' => 'IP Address successfully added'];
|
|
}
|
|
else{
|
|
$data = ['code' => 3, 'msg' => 'Your request could not be handled at this time'];
|
|
}
|
|
return response()->json($data, 200);
|
|
}
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$result = Models\NetworkOps::destroy($id);
|
|
if (request()->ajax()) {
|
|
$result_arr = ['code' => 1];
|
|
return response()->json($result_arr);
|
|
}
|
|
Session::flash('success_message', 'Network Operator successfully deleted!');
|
|
return redirect(route('mnos.index'));
|
|
}
|
|
}
|