update v1.0.7.9 R.C.

This is a Release Candidate. We are still testing.
This commit is contained in:
Sujit Prasad
2016-08-03 20:04:36 +05:30
parent 8b6b924d09
commit ffa56a43cb
3830 changed files with 181529 additions and 495353 deletions

View File

@@ -3,8 +3,8 @@
namespace App\Http\Controllers\Admin\helpdesk;
// controller
use App\Http\Controllers\Common\PhpMailController;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Common\PhpMailController;
// request
use App\Http\Requests\helpdesk\AgentRequest;
use App\Http\Requests\helpdesk\AgentUpdate;
@@ -139,12 +139,14 @@ class AgentController extends Controller
// fetch user credentails to send mail
$name = $user->user_name;
$email = $user->email;
try {
// send mail on registration
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
} catch (Exception $e) {
// returns if try fails
return redirect('agents')->with('warning', Lang::get('lang.agent_send_mail_error_on_agent_creation'));
if($request->input('send_email')) {
try {
// send mail on registration
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
} catch (Exception $e) {
// returns if try fails
return redirect('agents')->with('warning', Lang::get('lang.agent_send_mail_error_on_agent_creation'));
}
}
// returns for the success case
return redirect('agents')->with('success', Lang::get('lang.agent_creation_success'));

View File

@@ -54,7 +54,7 @@ class CloseWrokflowController extends Controller
$security = new WorkflowClose();
$securitys = $security->whereId($id)->first();
$securitys->days = $request->input('days');
// $securitys->condition = $request->input('condition');
// $securitys->condition = $request->input('condition');
$securitys->send_email = $request->input('send_email');
$securitys->status = $request->input('status');
$securitys->save();

View File

@@ -29,15 +29,14 @@ use Lang;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class DepartmentController extends Controller
{
class DepartmentController extends Controller {
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
public function __construct() {
$this->middleware('auth');
$this->middleware('roles');
}
@@ -49,11 +48,9 @@ class DepartmentController extends Controller
*
* @return type Response
*/
public function index(Department $department)
{
public function index(Department $department) {
try {
$departments = $department->get();
return view('themes.default1.admin.helpdesk.agent.departments.index', compact('departments'));
} catch (Exception $e) {
return view('404');
@@ -73,8 +70,7 @@ class DepartmentController extends Controller
*
* @return type Response
*/
public function create(User $user, Group_assign_department $group_assign_department, Department $department, Sla_plan $sla, Template $template, Emails $email, Groups $group)
{
public function create(User $user, Group_assign_department $group_assign_department, Department $department, Sla_plan $sla, Template $template, Emails $email, Groups $group) {
try {
$slas = $sla->get();
$user = $user->where('role', 'agent2')->get();
@@ -97,8 +93,7 @@ class DepartmentController extends Controller
*
* @return type Response
*/
public function store(Department $department, DepartmentRequest $request)
{
public function store(Department $department, DepartmentRequest $request) {
try {
$department->fill($request->except('group_id', 'manager', 'sla'))->save();
if ($request->sla) {
@@ -116,6 +111,11 @@ class DepartmentController extends Controller
/* Succes And Failure condition */
/* Check Whether the function Success or Fail */
if ($department->save() == true) {
if ($request->input('sys_department') == 'on') {
DB::table('settings_system')
->where('id', 1)
->update(['department' => $department->id]);
}
return redirect('departments')->with('success', Lang::get('lang.department_created_sucessfully'));
} else {
return redirect('departments')->with('fails', Lang::get('lang.failed_to_create_department'));
@@ -140,13 +140,12 @@ class DepartmentController extends Controller
*
* @return type Response
*/
public function edit($id, User $user, Group_assign_department $group_assign_department, Template $template, Teams $team, Department $department, Sla_plan $sla, Emails $email, Groups $group)
{
public function edit($id, User $user, Group_assign_department $group_assign_department, Template $template, Teams $team, Department $department, Sla_plan $sla, Emails $email, Groups $group) {
try {
$sys_department = \DB::table('settings_system')
->select('department')
->where('id', '=', 1)
->first();
->select('department')
->where('id', '=', 1)
->first();
$slas = $sla->get();
$user = $user->where('primary_dpt', $id)->get();
$emails = $email->get();
@@ -171,8 +170,7 @@ class DepartmentController extends Controller
*
* @return type Response
*/
public function update($id, Group_assign_department $group_assign_department, Department $department, DepartmentUpdate $request)
{
public function update($id, Group_assign_department $group_assign_department, Department $department, DepartmentUpdate $request) {
// dd($id);
try {
$table = $group_assign_department->where('department_id', $id);
@@ -198,8 +196,8 @@ class DepartmentController extends Controller
}
if ($request->input('sys_department') == 'on') {
DB::table('settings_system')
->where('id', 1)
->update(['department' => $id]);
->where('id', 1)
->update(['department' => $id]);
}
if ($departments->fill($request->except('group_access', 'manager', 'sla'))->save()) {
return redirect('departments')->with('success', Lang::get('lang.department_updated_sucessfully'));
@@ -220,9 +218,9 @@ class DepartmentController extends Controller
*
* @return type Response
*/
public function destroy($id, Department $department, Group_assign_department $group_assign_department, System $system, Tickets $tickets)
{
public function destroy($id, Department $department, Group_assign_department $group_assign_department, System $system, Tickets $tickets) {
// try {
$system = $system->where('id', '=', '1')->first();
if ($system->department == $id) {
return redirect('departments')->with('fails', Lang::get('lang.you_cannot_delete_default_department'));
@@ -234,7 +232,7 @@ class DepartmentController extends Controller
} else {
$text_tickets = 'Ticket';
}
$ticket = '<li>'.$tickets.' '.$text_tickets.Lang::get('lang.have_been_moved_to_default_department').'</li>';
$ticket = '<li>' . $tickets . ' ' . $text_tickets . Lang::get('lang.have_been_moved_to_default_department') . '</li>';
} else {
$ticket = '';
}
@@ -245,7 +243,7 @@ class DepartmentController extends Controller
} else {
$text_user = 'User';
}
$user = '<li>'.$users.' '.$text_user.Lang::get('lang.have_been_moved_to_default_department').'</li>';
$user = '<li>' . $users . ' ' . $text_user . Lang::get('lang.have_been_moved_to_default_department') . '</li>';
} else {
$user = '';
}
@@ -256,27 +254,28 @@ class DepartmentController extends Controller
} else {
$text_emails = 'Email';
}
$email = '<li>'.$emails.' System '.$text_emails.Lang::get('lang.have_been_moved_to_default_department').' </li>';
$email = '<li>' . $emails . ' System ' . $text_emails . Lang::get('lang.have_been_moved_to_default_department') . ' </li>';
} else {
$email = '';
}
$helptopic = DB::table('help_topic')->where('department', '=', $id)->update(['department' => null], ['status' => '1']);
if ($helptopic > 0) {
$helptopic = '<li>'.Lang::get('lang.the_associated_helptopic_has_been_deactivated').'</li>';
$helptopic = '<li>' . Lang::get('lang.the_associated_helptopic_has_been_deactivated') . '</li>';
} else {
$helptopic = '';
}
$message = $ticket.$user.$email.$helptopic;
$message = $ticket . $user . $email . $helptopic;
/* Becouse of foreign key we delete group_assign_department first */
$group_assign_department = $group_assign_department->where('department_id', $id);
$group_assign_department->delete();
$departments = $department->whereId($id)->first();
/* Check the function is Success or Fail */
if ($departments->delete() == true) {
return redirect('departments')->with('success', Lang::get('lang.department_deleted_sucessfully').$message);
return redirect('departments')->with('success', Lang::get('lang.department_deleted_sucessfully') . $message);
} else {
return redirect('departments')->with('fails', Lang::get('lang.department_can_not_delete'));
}
}
}
}

View File

@@ -498,7 +498,7 @@ class EmailsController extends Controller
$mailbox_protocol = $fetching_encryption2;
$host = $request->input('fetching_host');
$port = $request->input('fetching_port');
$mailbox = '{'.$host.':'.$port.$mailbox_protocol.'}INBOX';
$mailbox = '{'.$host.':'.$port.$fetching_protocol.$mailbox_protocol.'}INBOX';
} else {
$mailbox_protocol = $fetching_protocol.$fetching_encryption;
$host = $request->input('fetching_host');

View File

@@ -1,7 +1,5 @@
<?php
namespace App\Http\Controllers\Admin\helpdesk;
// Controller
use App\Http\Controllers\Controller;
// Model
@@ -14,7 +12,6 @@ use Illuminate\Http\Request;
use Input;
use Lang;
use Redirect;
/**
* FormController
* This controller is used to CRUD Custom Forms.
@@ -25,14 +22,12 @@ class FormController extends Controller
{
private $fields;
private $forms;
public function __construct(Fields $fields, Forms $forms)
{
$this->fields = $fields;
$this->forms = $forms;
$this->middleware('auth');
}
/**
* home.
*
@@ -42,7 +37,6 @@ class FormController extends Controller
{
return view('forms.home');
}
/**
* list of forms.
*
@@ -58,7 +52,6 @@ class FormController extends Controller
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* create a new form.
*
@@ -72,7 +65,6 @@ class FormController extends Controller
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* Show a new form.
*
@@ -88,7 +80,6 @@ class FormController extends Controller
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* Store a new form.
*
@@ -124,10 +115,8 @@ class FormController extends Controller
}
}
Fields::insert($fields);
return Redirect::back()->with('success', Lang::get('lang.successfully_created_form'));
}
/**
* Delete Form.
*
@@ -151,7 +140,6 @@ class FormController extends Controller
}
$forms = $forms->where('id', $id)->first();
$forms->delete();
return redirect()->back()->with('success', Lang::get('lang.form_deleted_successfully'));
}
}
}

View File

@@ -40,7 +40,7 @@ class HelptopicController extends Controller
}
/**
* Display a listing of the resource.
* Display a listing of the helptopic.
*
* @param type Help_topic $topic
*
@@ -58,7 +58,7 @@ class HelptopicController extends Controller
}
/**
* Show the form for creating a new resource.
* Show the form for creating a new helptopic.
*
* @param type Priority $priority
* @param type Department $department
@@ -96,7 +96,7 @@ class HelptopicController extends Controller
}
/**
* Store a newly created resource in storage.
* Store a newly created helptpoic in storage.
*
* @param type Help_topic $topic
* @param type HelptopicRequest $request
@@ -128,7 +128,7 @@ class HelptopicController extends Controller
}
/**
* Show the form for editing the specified resource.
* Show the form for editing the specified helptopic.
*
* @param type $id
* @param type Priority $priority
@@ -160,7 +160,7 @@ class HelptopicController extends Controller
}
/**
* Update the specified resource in storage.
* Update the specified helptopic in storage.
*
* @param type $id
* @param type Help_topic $topic
@@ -201,7 +201,7 @@ class HelptopicController extends Controller
}
/**
* Remove the specified resource from storage.
* Remove the specified helptopic from storage.
*
* @param type int $id
* @param type Help_topic $topic

View File

@@ -98,7 +98,12 @@ class LanguageController extends Controller
$values = array_slice($values, 2); // skips array element $value[0] = '.' & $value[1] = '..'
return \Datatable::collection(new Collection($values))
->addColumn('language', function ($model) {
return Config::get('languages.'.$model);
if ($model == Config::get('app.fallback_locale')) {
return Config::get('languages.'.$model).' ('.Lang::get('lang.default').')';
} else {
return Config::get('languages.'.$model);
}
})
->addColumn('id', function ($model) {
return $model;
@@ -228,24 +233,29 @@ class LanguageController extends Controller
public function deleteLanguage($lang)
{
if ($lang !== App::getLocale()) {
$deletePath = base_path('resources/lang').'/'.$lang; //define file path to delete
$success = File::deleteDirectory($deletePath); //remove extracted folder and it's subfolder from lang
if ($success) {
//sending back with success message
Session::flash('success', Lang::get('lang.delete-success'));
return Redirect::back();
if ($lang !== Config::get('app.fallback_locale')) {
$deletePath = base_path('resources/lang').'/'.$lang; //define file path to delete
$success = File::deleteDirectory($deletePath); //remove extracted folder and it's subfolder from lang
if ($success) {
//sending back with success message
Session::flash('success', Lang::get('lang.delete-success'));
return Redirect::back();
} else {
//sending back with error message
Session::flash('fails', Lang::get('lang.lang-doesnot-exist'));
return Redirect::back();
}
} else {
//sending back with error message
Session::flash('fails', Lang::get('lang.lang-doesnot-exist'));
return Redirect::back();
Session::flash('fails', Lang::get('lang.lang-fallback-lang'));
return redirect('languages');
}
} else {
//sending back with error message
Session::flash('fails', Lang::get('lang.active-lang-error'));
return redirect('languages');
}
}
}

View File

@@ -64,10 +64,10 @@ class SecurityController extends Controller
*
* @return Response
*/
public function show($id)
{
return view('themes.default1.admin.helpdesk.setting.security.preview', compact('id'));
}
// public function show($id)
// {
// return view('themes.default1.admin.helpdesk.setting.security.preview', compact('id'));
// }
/**
* Update security details.

View File

@@ -30,6 +30,7 @@ use App\Model\helpdesk\Utility\Date_time_format;
use App\Model\helpdesk\Utility\Time_format;
use App\Model\helpdesk\Utility\Timezones;
use App\Model\helpdesk\Workflow\WorkflowClose;
use App\Model\helpdesk\Settings\CommonSettings;
use DateTime;
// classes
use DB;
@@ -93,7 +94,7 @@ class SettingsController extends Controller
$companys = $company->whereId('1')->first();
if (Input::file('logo')) {
$name = Input::file('logo')->getClientOriginalName();
$destinationPath = 'lb-faveo/media/company/';
$destinationPath = 'uploads/company/';
$fileName = rand(0000, 9999).'.'.$name;
Input::file('logo')->move($destinationPath, $fileName);
$companys->logo = $fileName;
@@ -145,7 +146,7 @@ class SettingsController extends Controller
*
* @return type Response
*/
public function getsystem(System $system, Department $department, Timezones $timezone, Date_format $date, Date_time_format $date_time, Time_format $time)
public function getsystem(System $system, Department $department, Timezones $timezone, Date_format $date, Date_time_format $date_time, Time_format $time, CommonSettings $common_settings)
{
try {
/* fetch the values of system from system table */
@@ -154,11 +155,11 @@ class SettingsController extends Controller
$departments = $department->get();
/* Fetch the values from Timezones table */
$timezones = $timezone->get();
//$debug = \Config::get('app.debug');
//dd($value);
/* Fetch status value of common settings */
$common_setting = $common_settings->select('status')->where('option_name', '=', 'user_set_ticket_status')->first();
// /dd($common_setting);
/* Direct to System Settings Page */
return view('themes.default1.admin.helpdesk.settings.system', compact('systems', 'departments', 'timezones', 'time', 'date', 'date_time'));
return view('themes.default1.admin.helpdesk.settings.system', compact('systems', 'departments', 'timezones', 'time', 'date', 'date_time', 'common_setting'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -176,16 +177,26 @@ class SettingsController extends Controller
public function postsystem($id, System $system, SystemRequest $request)
{
try {
// dd($request);
//dd($request->user_set_ticket_status);
/* fetch the values of system request */
$systems = $system->whereId('1')->first();
/* fill the values to coompany table */
/* Check whether function success or not */
$systems->fill($request->input())->save();
/* redirect to Index page with Success Message */
$rtl = CommonSettings::where('option_name', '=', 'enable_rtl')->first();
if($request->enable_rtl != null) {
$rtl->option_value = 1;
} else {
$rtl->option_value = 0;
}
$rtl->save();
// dd($datacontent);
//\Config::set('app.debug', $request->input('debug'));
$usts = CommonSettings::where('option_name', '=', 'user_set_ticket_status')->first();
if ($usts->status != $request->user_set_ticket_status){
$usts->status = $request->user_set_ticket_status;
$usts->save();
}
/* redirect to Index page with Success Message */
return redirect('getsystem')->with('success', Lang::get('lang.system_updated_successfully'));
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
@@ -220,7 +231,7 @@ class SettingsController extends Controller
}
/**
* Update the specified resource in storage.
* Update the specified Ticket in storage.
*
* @param type int $id
* @param type Ticket $ticket
@@ -280,7 +291,7 @@ class SettingsController extends Controller
}
/**
* Update the specified resource in storage.
* Update the specified email setting in storage.
*
* @param type int $id
* @param type Email $email
@@ -339,7 +350,7 @@ class SettingsController extends Controller
}
/**
* Update the specified resource in storage for cron job.
* Update the specified schedular in storage for cron job.
*
* @param type Email $email
* @param type EmailRequest $request
@@ -399,7 +410,7 @@ class SettingsController extends Controller
}
/**
* Update the specified resource in storage.
* Update the specified autoresponse in storage.
*
* @param type Responder $responder
* @param type Request $request
@@ -448,7 +459,7 @@ class SettingsController extends Controller
}
/**
* Update the specified resource in storage.
* Update the specified alert in storage.
*
* @param type $id
* @param type Alert $alert

View File

@@ -221,7 +221,7 @@ class SettingsController2 extends Controller
$companys = $company->whereId('1')->first();
if (Input::file('logo')) {
$name = Input::file('logo')->getClientOriginalName();
$destinationPath = 'lb-faveo/media/company/';
$destinationPath = 'uploads/company/';
$fileName = rand(0000, 9999).'.'.$name;
Input::file('logo')->move($destinationPath, $fileName);
$companys->logo = $fileName;

View File

@@ -13,6 +13,7 @@ use App\Http\Requests\helpdesk\TemplateUdate;
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Email\Template;
use App\Model\helpdesk\Utility\Languages;
use App\Model\helpdesk\Settings\CommonSettings;
// classes
use Exception;
use Illuminate\Http\Request;
@@ -326,9 +327,17 @@ class TemplateController extends Controller
$mail->SetFrom($email_details->email_address, $email_details->email_name); // sender details
$address = $request->to; // receiver email
$mail->AddAddress($address);
$mail->Subject = utf8_decode($request->subject); // subject of the email
$body = utf8_decode($request->message); // body of the email
$mail->MsgHTML($body);
$mail->Subject = $request->subject; // subject of the email
$body = $request->message; // body of the email
$mail->CharSet = "utf8";
// $mail->MsgHTML($body);
// $body = $request->message;
$rtl = CommonSettings::where('option_name', '=', 'enable_rtl')->first();
if($rtl->option_value == 1) {
$mail->ContentType = 'text/html';
$body = '<html dir="rtl" xml:lang="ar" lang="ar"><head></head><body dir="rtl">' . $body . '</body></html>';
} else {
}
if (!$mail->Send()) {
$return = Lang::get('lang.mailer_error').': '.$mail->ErrorInfo;
} else {
@@ -355,15 +364,22 @@ class TemplateController extends Controller
$mail->setFrom($email_details->email_address, $email_details->email_name);
$mail->addAddress($request->to, ''); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = utf8_decode($request->subject);
$mail->Body = utf8_decode($request->message);
$mail->CharSet = "utf8";
$mail->Subject = $request->subject;
$body = $request->message;
$rtl = CommonSettings::where('option_name', '=', 'enable_rtl')->first();
if($rtl->option_value == 1) {
$mail->ContentType = 'text/html';
$body = '<html dir="rtl" xml:lang="ar" lang="ar"><head></head><body dir="rtl">' . $body . '</body></html>';
} else {
}
$mail->Body = $body;
if (!$mail->send()) {
$return = Lang::get('lang.mailer_error').': '.$mail->ErrorInfo;
} else {
$return = Lang::get('lang.message_has_been_sent');
}
}
return redirect()->back()->with('success', $return);
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());

View File

@@ -6,7 +6,7 @@ namespace App\Http\Controllers\Admin\helpdesk;
use App\Http\Controllers\Controller;
// models
use App\Model\helpdesk\Priority;
use App\Model\helpdesk\Ticket_thread;
use App\Model\helpdesk\Ticket_Thread;
// classes
use Exception;
@@ -25,7 +25,7 @@ class ThreadController extends Controller
*
* @return type Response
*/
public function getTickets(Ticket_thread $thread, Priority $priority)
public function getTickets(Ticket_Thread $thread, Priority $priority)
{
try {
/* get the values of Ticket_thread from Ticket_thread Table */

View File

@@ -132,7 +132,7 @@ class WorkflowController extends Controller
->addColumn('Actions', function ($model) {
$confirmation = 'Are you sure?';
return "<a class='btn btn-info btn-xs btn-flat' href='".route('workflow.edit', $model->id)."'><i class='fa fa-edit text-black'></i> Edit</a> <a class='btn btn-danger btn-xs btn-flat' href='".route('workflow.delete', $model->id)."'><i class='fa fa-trash text-black'></i> Delete</a>";
return "<a class='btn btn-info btn-xs btn-flat' href='".route('workflow.edit', $model->id)."'><i class='fa fa-edit text-black'></i> Edit</a> <a class='btn btn-danger btn-xs btn-flat' href='".route('workflow.delete', $model->id)."' onclick='return confirm_delete()'><i class='fa fa-trash text-black'></i> Delete</a> ";
})
->make();
}

View File

@@ -27,16 +27,15 @@ use PhpImap\Mailbox as ImapMailbox;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class MailController extends Controller
{
class MailController extends Controller {
/**
* constructor
* Create a new controller instance.
*
* @param type TicketController $TicketController
*/
public function __construct(TicketWorkflowController $TicketWorkflowController)
{
public function __construct(TicketWorkflowController $TicketWorkflowController) {
$this->middleware('board');
$this->TicketWorkflowController = $TicketWorkflowController;
}
@@ -46,13 +45,12 @@ class MailController extends Controller
*
* @return type
*/
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket)
{
public function readmails(Emails $emails, Email $settings_email, System $system, Ticket $ticket) {
// $path_url = $system->first()->url;
if ($settings_email->first()->email_fetching == 1) {
if ($settings_email->first()->all_emails == 1) {
// $helptopic = $this->TicketController->default_helptopic();
// $sla = $this->TicketController->default_sla();
// $sla = $this->TicketController->default_sla();
$email = $emails->get();
foreach ($email as $e_mail) {
if ($e_mail->fetching_status == 1) {
@@ -82,7 +80,7 @@ class MailController extends Controller
$protocol = $fetching_encryption2;
} else {
if ($e_mail->fetching_protocol) {
$fetching_protocol = '/'.$e_mail->fetching_protocol;
$fetching_protocol = '/' . $e_mail->fetching_protocol;
} else {
$fetching_protocol = '';
}
@@ -91,21 +89,38 @@ class MailController extends Controller
} else {
$fetching_encryption = '';
}
$protocol = $fetching_protocol.$fetching_encryption;
$protocol = $fetching_protocol . $fetching_encryption;
}
$imap_config = '{'.$host.':'.$port.$protocol.'}INBOX';
$imap_config = '{' . $host . ':' . $port . $protocol . '}INBOX';
$password = Crypt::decrypt($e_mail->password);
$mailbox = new ImapMailbox($imap_config, $e_mail->email_address, $password, __DIR__);
try {
$mailbox = new ImapMailbox($imap_config, $e_mail->email_address, $password, __DIR__);
} catch (\PhpImap\Exception $e) {
echo "Connection error";
}
$mails = [];
$mailsIds = $mailbox->searchMailBox('SINCE '.date('d-M-Y', strtotime('-1 day')));
try {
$mailsIds = $mailbox->searchMailBox('SINCE ' . date('d-M-Y', strtotime('-1 day')));
} catch (\PhpImap\Exception $e) {
echo "Connection error";
}
if (!$mailsIds) {
die('Mailbox is empty');
}
foreach ($mailsIds as $mailId) {
$overview = $mailbox->get_overview($mailId);
try {
$overview = $mailbox->get_overview($mailId);
} catch (Exception $e) {
return \Lang::get('lang.unable_to_fetch_emails');
}
$var = $overview[0]->seen ? 'read' : 'unread';
if ($var == 'unread') {
$mail = $mailbox->getMail($mailId);
try {
$mail = $mailbox->getMail($mailId);
} catch (\PhpImap\Exception $e) {
echo "Connection error";
}
if ($settings_email->first()->email_collaborator == 1) {
$collaborator = $mail->cc;
} else {
@@ -121,14 +136,24 @@ class MailController extends Controller
}
if ($body == null) {
$attach = $mail->getAttachments();
$path = $attach['html-body']->filePath;
if ($path == null) {
$path = $attach['text-body']->filePath;
if (is_array($attach)) {
if (key_exists('html-body', $attach)) {
$path = $attach['html-body']->filePath;
}
if ($path == null) {
if (key_exists('text-body', $attach)) {
$path = $attach['text-body']->filePath;
}
}
if ($path) {
$body = file_get_contents($path);
}
if ($body) {
$body = self::trimTableTag($body);
} else {
$body = "";
}
}
$body = file_get_contents($path);
//dd($body);
$body = self::trimTableTag($body);
}
// if ($body == null) {
// $body = $mailbox->backup_getmail($mailId);
@@ -137,10 +162,10 @@ class MailController extends Controller
$date = $mail->date;
$datetime = $overview[0]->date;
$date_time = explode(' ', $datetime);
$date = $date_time[1].'-'.$date_time[2].'-'.$date_time[3].' '.$date_time[4];
$date = $date_time[1] . '-' . $date_time[2] . '-' . $date_time[3] . ' ' . $date_time[4];
$date = date('Y-m-d H:i:s', strtotime($date));
if (isset($mail->subject)) {
$subject = utf8_decode($mail->subject);
$subject = $mail->subject;
} else {
$subject = 'No Subject';
}
@@ -156,57 +181,57 @@ class MailController extends Controller
$team_assign = null;
$ticket_status = null;
$result = $this->TicketWorkflowController->workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response);
// dd($result);
if ($result[1] == true) {
$ticket_table = Tickets::where('ticket_number', '=', $result[0])->first();
$thread_id = Ticket_Thread::where('ticket_id', '=', $ticket_table->id)->max('id');
// $thread_id = Ticket_Thread::whereRaw('id = (select max(`id`) from ticket_thread)')->first();
$thread_id = $thread_id;
foreach ($mail->getAttachments() as $attachment) {
$support = 'support';
// echo $_SERVER['DOCUMENT_ROOT'];
$dir_img_paths = __DIR__;
$dir_img_path = explode('/code', $dir_img_paths);
// dd($attachment->filePath);
$filepath = explode('../../../../../public', $attachment->filePath);
// var_dump($attachment->filePath);
// dd($filepath);
// $path = $dir_img_path[0]."/code/public/".$filepath[1];
$path = public_path().$filepath[1];
// dd($path);
$filesize = filesize($path);
$file_data = file_get_contents($path);
$ext = pathinfo($attachment->filePath, PATHINFO_EXTENSION);
$imageid = $attachment->id;
$string = str_replace('-', '', $attachment->name);
$filename = explode('src', $attachment->filePath);
$filename = str_replace('\\', '', $filename);
$body = str_replace('cid:'.$imageid, $filepath[1], $body);
$pos = strpos($body, $filepath[1]);
if ($pos == false) {
if ($settings_email->first()->attachment == 1) {
$filepath = explode('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public', $attachment->filePath);
if ($filepath[1]) {
$path = public_path() . $filepath[1];
$filesize = filesize($path);
$file_data = file_get_contents($path);
$ext = pathinfo($attachment->filePath, PATHINFO_EXTENSION);
$imageid = $attachment->id;
$string = str_replace('-', '', $attachment->name);
$filename = explode('src', $attachment->filePath);
$filename = str_replace('\\', '', $filename);
$body = str_replace('cid:' . $imageid, $filepath[1], $body);
$pos = strpos($body, $filepath[1]);
if ($pos == false) {
if ($settings_email->first()->attachment == 1) {
$upload = new Ticket_attachments();
$upload->file = $file_data;
$upload->thread_id = $thread_id;
$upload->name = $filepath[1];
$upload->type = $ext;
$upload->size = $filesize;
$upload->poster = 'ATTACHMENT';
$upload->save();
}
} else {
$upload = new Ticket_attachments();
$upload->file = $file_data;
$upload->thread_id = $thread_id;
$upload->name = $filepath[1];
$upload->type = $ext;
$upload->size = $filesize;
$upload->poster = 'ATTACHMENT';
$upload->poster = 'INLINE';
$upload->save();
}
} else {
$upload = new Ticket_attachments();
$upload->file = $file_data;
$upload->thread_id = $thread_id;
$upload->name = $filepath[1];
$upload->type = $ext;
$upload->size = $filesize;
$upload->poster = 'INLINE';
$upload->save();
unlink($path);
}
unlink($path);
}
$body = Encoding::fixUTF8($body);
$body = $body;
$thread = Ticket_Thread::where('id', '=', $thread_id)->first();
$thread->body = $this->separate_reply($body);
$thread->save();
@@ -226,8 +251,7 @@ class MailController extends Controller
*
* @return type string
*/
public function separate_reply($body)
{
public function separate_reply($body) {
$body2 = explode('---Reply above this line---', $body);
$body3 = $body2[0];
@@ -241,8 +265,7 @@ class MailController extends Controller
*
* @return type string
*/
public function decode_imap_text($str)
{
public function decode_imap_text($str) {
$result = '';
$decode_header = imap_mime_header_decode($str);
foreach ($decode_header as $obj) {
@@ -257,8 +280,7 @@ class MailController extends Controller
*
* @return type
*/
public function fetch_attachments()
{
public function fetch_attachments() {
$uploads = Upload::all();
foreach ($uploads as $attachment) {
$image = @imagecreatefromstring($attachment->file);
@@ -266,8 +288,8 @@ class MailController extends Controller
imagejpeg($image, null, 80);
$data = ob_get_contents();
ob_end_clean();
$var = '<a href="" target="_blank"><img src="data:image/jpg;base64,'.base64_encode($data).'"/></a>';
echo '<br/><span class="mailbox-attachment-icon has-img">'.$var.'</span>';
$var = '<a href="" target="_blank"><img src="data:image/jpg;base64,' . base64_encode($data) . '"/></a>';
echo '<br/><span class="mailbox-attachment-icon has-img">' . $var . '</span>';
}
}
@@ -278,19 +300,17 @@ class MailController extends Controller
*
* @return type file
*/
public function get_data($id)
{
public function get_data($id) {
$attachments = App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->get();
foreach ($attachments as $attachment) {
header('Content-type: application/'.$attachment->type.'');
header('Content-Disposition: inline; filename='.$attachment->name.'');
header('Content-type: application/' . $attachment->type . '');
header('Content-Disposition: inline; filename=' . $attachment->name . '');
header('Content-Transfer-Encoding: binary');
echo $attachment->file;
}
}
public static function trimTableTag($html)
{
public static function trimTableTag($html) {
if (strpos('<table>', $html) != false) {
$first_pos = strpos($html, '<table');
$fist_string = substr_replace($html, '', 0, $first_pos);
@@ -306,15 +326,13 @@ class MailController extends Controller
return $html;
}
public static function trim3D($html)
{
public static function trim3D($html) {
$body = str_replace('=3D', '', $html);
return $body;
}
public static function trimInjections($html, $tags = ['<script>', '</script>', '<style>', '</style>', '<?php', '?>'])
{
public static function trimInjections($html, $tags = ['<script>', '</script>', '<style>', '</style>', '<?php', '?>']) {
$replace = [];
foreach ($tags as $key => $tag) {
$replace[$key] = htmlspecialchars($tag);
@@ -323,4 +341,5 @@ class MailController extends Controller
return $body;
}
}

View File

@@ -22,18 +22,16 @@ use View;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class NotificationController extends Controller
{
public function __construct(PhpMailController $PhpMailController)
{
class NotificationController extends Controller {
public function __construct(PhpMailController $PhpMailController) {
$this->PhpMailController = $PhpMailController;
}
/**
* This function is for sending daily report/notification about the system.
* */
public function send_notification()
{
public function send_notification() {
//fetching email settings
$email = Email::where('id', '=', '1')->first();
// checking if the daily notification is enabled or not
@@ -42,6 +40,7 @@ class NotificationController extends Controller
$notification = Log_notification::where('log', '=', 'NOT-1')->orderBy('id', 'DESC')->first();
$date = explode(' ', $notification->created_at);
if (date('Y-m-d') == $date[0]) {
} else {
// creating a daily notification log
Log_notification::create(['log' => 'NOT-1']);
@@ -49,11 +48,11 @@ class NotificationController extends Controller
// Send notification details to admin
$this->send_notification_to_admin($company);
// Send notification details to team lead
$this->send_notification_to_team_lead($company);
//$this->send_notification_to_team_lead($company);
// Send notification details to manager of a department
$this->send_notification_to_manager($company);
//$this->send_notification_to_manager($company);
// Send notification details to all the agents
$this->send_notification_to_agent($company);
//$this->send_notification_to_agent($company);
}
}
}
@@ -65,21 +64,27 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_admin($company)
{
public function send_notification_to_admin($company) {
// get all admin users
$users = User::where('role', '=', 'admin')->get();
foreach ($users as $user) {
// Send notification details to admin
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.admin', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.admin', ['company' => $company, 'name' => $user_name], function ($message) use ($email, $user_name, $company) {
// $message->to($email, $user_name)->subject($company.' Daily Report ');
// });
$from = $this->PhpMailController->mailfrom('1', '0');
$to = [
'name' => $user_name,
'email' => $email
];
$message = [
'subject' => 'Daily Report',
'scenario' => null,
'body' => $contents
];
$this->dispatch((new \App\Jobs\SendEmail($from, $to, $message))->onQueue('emails'));
//$this->PhpMailController->sendEmail($from,$to,$message);
}
}
@@ -88,8 +93,7 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_manager($company)
{
public function send_notification_to_manager($company) {
// get all department managers
$depts = Department::all();
foreach ($depts as $dept) {
@@ -99,14 +103,10 @@ class NotificationController extends Controller
foreach ($users as $user) {
// Send notification details to manager of a department
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.manager', ['company' => $company, 'name' => $user_name]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.manager', ['company' => $company, 'name' => $user_name, 'dept_id' => $dept->id, 'dept_name' => $dept->name], function ($message) use ($email, $user_name, $company, $dept_name) {
// $message->to($email, $user_name)->subject($company.' Daily Report for department manager of '.$dept_name.' department.');
// });
}
}
}
@@ -117,8 +117,7 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_team_lead($company)
{
public function send_notification_to_team_lead($company) {
// get all Team leads
$teams = Teams::all();
foreach ($teams as $team) {
@@ -128,14 +127,10 @@ class NotificationController extends Controller
foreach ($users as $user) {
// Send notification details to team lead
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$view = View::make('emails.notifications.lead', ['company' => $company, 'name' => $user_name]);
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.lead', ['company' => $company, 'name' => $user_name, 'team_id' => $team->id]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.lead', ['company' => $company, 'name' => $user_name, 'team_id' => $team->id], function ($message) use ($email, $user_name, $company, $team_name) {
// $message->to($email, $user_name)->subject($company.' Daily Report for Team Lead of team '.$team_name);
// });
}
}
}
@@ -146,21 +141,16 @@ class NotificationController extends Controller
*
* @return mail
* */
public function send_notification_to_agent($company)
{
public function send_notification_to_agent($company) {
// get all agents users
$users = User::where('role', '=', 'agent')->get();
foreach ($users as $user) {
// Send notification details to all the agents
$email = $user->email;
$user_name = $user->first_name.' '.$user->last_name;
$user_name = $user->first_name . ' ' . $user->last_name;
$view = View::make('emails.notifications.agent', ['company' => $company, 'name' => $user_name, 'user_id' => $user->id]);
$contents = $view->render();
$this->PhpMailController->sendEmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => 'Daily Report', 'scenario' => null, 'body' => $contents]);
// \Mail::send('emails.notifications.agent', ['company' => $company, 'name' => $user_name, 'user_id' => 1], function ($message) use ($email, $user_name, $company) {
// $message->to($email, $user_name)->subject($company.' Daily Report for Agents');
// });
}
}
@@ -169,8 +159,7 @@ class NotificationController extends Controller
*
* @return type variable
*/
public function company()
{
public function company() {
// fetching comapny model
$company = Company::Where('id', '=', '1')->first();
// fetching company name
@@ -183,12 +172,4 @@ class NotificationController extends Controller
return $company;
}
// // testing
// public function test(){
// $email = "sujit.prasad@ladybirdweb.com";
// $user_name = "sujit prasad";
// \Mail::send('emails.notifications.test', ['user_id' => 1], function ($message) use($email, $user_name) {
// $message->to($email, $user_name)->subject('testing reporting');
// });
// }
}

View File

@@ -28,7 +28,6 @@ class Ticket2Controller extends Controller
*/
public function __construct()
{
SettingsController::smtp();
$this->middleware('auth');
}
@@ -51,6 +50,11 @@ class Ticket2Controller extends Controller
}
}
/**
* this function returns the list of open tickets of a particular department
* @param type $id
* @return type
*/
public function getOpenTickets($id)
{
if (Auth::user()->role == 'admin') {
@@ -59,7 +63,6 @@ class Ticket2Controller extends Controller
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('dept_id', '=', $dept->id)->get();
}
return Ttable::getTable($tickets);
}
@@ -81,23 +84,27 @@ class Ticket2Controller extends Controller
return view('themes.default1.agent.helpdesk.dept-ticket.closed', compact('id'));
}
}
/**
* this function returns the list of close tickets of a particular department
* @param type $id
* @return type
*/
public function getCloseTickets($id)
{
if (Auth::user()->role == 'admin') {
$tickets = Tickets::where('status', '=', '2')->where('dept_id', '=', $id)->get();
$tickets = Tickets::where('status', '=', '2')->where('status', '=', '3')->where('dept_id', '=', $id)->get();
} else {
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('status', '=', '2')->where('dept_id', '=', $dept->id)->get();
$tickets = Tickets::where('status', '=', '2')->where('status', '=', '3')->where('dept_id', '=', $dept->id)->get();
}
return Ttable::getTable($tickets);
}
/**
* Show the Inbox ticket list page.
*
* @return type response
* this function returns the list of close tickets of a particular department
* @param type $id
* @return type
*/
public function deptinprogress($id)
{
@@ -129,4 +136,5 @@ class Ticket2Controller extends Controller
return Ttable::getTable($tickets);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -350,7 +350,6 @@ class TicketWorkflowController extends Controller
$ticket_settings_details = $this->changeStatus($workflow_action, $ticket_settings_details);
}
}
return $ticket_settings_details;
}

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
use App\Http\Controllers\Common\PhpMailController;
// requests
/* Include Sys_user Model */
use App\Http\Requests\helpdesk\ProfilePassword;
@@ -44,8 +45,9 @@ class UserController extends Controller
*
* @return void
*/
public function __construct()
public function __construct(PhpMailController $PhpMailController)
{
$this->PhpMailController = $PhpMailController;
// checking authentication
$this->middleware('auth');
// checking if role is agent
@@ -77,7 +79,7 @@ class UserController extends Controller
public function user_list()
{
// displaying list of users with chumper datatables
return \Datatable::collection(User::where('role', '!=', 'admin')->where('role', '!=', 'agent')->get())
return \Datatable::collection(User::where('role',"=","user")->get())
/* searchable column username and email */
->searchColumns('user_name', 'email', 'phone')
/* order column username and email */
@@ -179,13 +181,17 @@ class UserController extends Controller
/* insert the input request to sys_user table */
/* Check whether function success or not */
$user->email = $request->input('email');
$user->user_name = $request->input('full_name');
$user->first_name = $request->input('first_name');
$user->last_name = $request->input('last_name');
$user->user_name = $request->input('user_name');
$user->mobile = $request->input('mobile');
$user->ext = $request->input('ext');
$user->phone_number = $request->input('phone_number');
$user->country_code = $request->input('country_code');
$user->active = $request->input('active');
$user->internal_note = $request->input('internal_note');
$password = $this->generateRandomString();
$user->password = Hash::make($password);
$user->role = 'user';
try {
if ($request->get('country_code') == '' && ($request->get('phone_number') != '' || $request->get('mobile') != '')) {
@@ -196,7 +202,24 @@ class UserController extends Controller
return redirect()->back()->with(['fails' => Lang::get('lang.incorrect-country-code-error'), 'country_code_error' => 1])->withInput();
}
}
$user->save();
// save user credentails
if ($user->save() == true) {
// fetch user credentails to send mail
$name = $user->user_name;
$email = $user->email;
if($request->input('send_email')) {
try {
// send mail on registration
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
} catch (Exception $e) {
// returns if try fails
return redirect('user')->with('warning', Lang::get('lang.user_send_mail_error_on_user_creation'));
}
}
// returns for the success case
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
}
// $user->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', Lang::get('lang.User-Created-Successfully'));
} catch (Exception $e) {
@@ -260,6 +283,7 @@ class UserController extends Controller
*/
public function update($id, Sys_userUpdate $request)
{
// dd($request);
$user = new User();
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
@@ -336,11 +360,11 @@ class UserController extends Controller
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
$destinationPath = 'lb-faveo/media/profilepic';
$destinationPath = 'uploads/profilepic';
$user->profile_pic = $name;
} elseif ($request->input('gender') == 0) {
$name = 'avatar2.png';
$destinationPath = 'lb-faveo/media/profilepic';
$destinationPath = 'uploads/profilepic';
$user->profile_pic = $name;
}
}
@@ -349,7 +373,7 @@ class UserController extends Controller
// fetching picture name
$name = Input::file('profile_pic')->getClientOriginalName();
// fetching upload destination path
$destinationPath = 'lb-faveo/media/profilepic';
$destinationPath = 'uploads/profilepic';
// adding a random value to profile picture filename
$fileName = rand(0000, 9999).'.'.$name;
// moving the picture to a destination folder
@@ -486,4 +510,29 @@ class UserController extends Controller
return 0;
}
}
/**
* Generate a random string for password.
*
* @param type $length
*
* @return string
*/
public function generateRandomString($length = 10)
{
// list of supported characters
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// character length checked
$charactersLength = strlen($characters);
// creating an empty variable for random string
$randomString = '';
// fetching random string
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
// return random string
return $randomString;
}
}

View File

@@ -1,427 +0,0 @@
<?php
namespace App\Http\Controllers\Agent\helpdesk;
// controllers
use App\Http\Controllers\Controller;
// requests
/* Include Sys_user Model */
use App\Http\Requests\helpdesk\ProfilePassword;
/* For validation include Sys_userRequest in create */
use App\Http\Requests\helpdesk\ProfileRequest;
/* For validation include Sys_userUpdate in update */
use App\Http\Requests\helpdesk\Sys_userRequest;
/* include guest_note model */
use App\Http\Requests\helpdesk\Sys_userUpdate;
// models
use App\Model\helpdesk\Agent_panel\Organization;
use App\Model\helpdesk\Agent_panel\User_org;
use App\User;
// classes
use Auth;
use Exception;
use Hash;
use Input;
use Redirect;
/**
* UserController
* This controller is used to CRUD an User details, and proile management of an agent.
*
* @author Ladybird <info@ladybirdweb.com>
*/
class UserController2 extends Controller
{
/**
* Create a new controller instance.
* constructor to check
* 1. authentication
* 2. user roles
* 3. roles must be agent.
*
* @return void
*/
public function __construct()
{
// checking authentication
$this->middleware('auth');
// checking if role is agent
$this->middleware('role.agent');
}
/**
* Display all list of the users.
*
* @param type User $user
*
* @return type view
*/
public function index()
{
try {
/* get all values in Sys_user */
return view('themes.default1.agent.helpdesk.user.index');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* This function is used to display the list of users using chumper datatables.
*
* @return datatable
*/
public function user_list()
{
// displaying list of users with chumper datatables
return \Datatable::collection(User::where('role', '!=', 'admin')->where('role', '!=', 'agent')->get())
/* searchable column username and email*/
->searchColumns('user_name', 'email', 'phone')
/* order column username and email */
->orderColumns('user_name', 'email')
/* column username */
->addColumn('user_name', function ($model) {
if (strlen($model->user_name) > 20) {
$username = substr($model->user_name, 0, 30);
$username = substr($username, 0, strrpos($username, ' ')).' ...';
} else {
$username = "<a href='".route('user.edit', $model->id)."'>".$model->user_name.'</a>';
}
return $username;
})
/* column email */
->addColumn('email', function ($model) {
$email = "<a href='".route('user.edit', $model->id)."'>".$model->email.'</a>';
return $email;
})
/* column phone */
->addColumn('phone', function ($model) {
$phone = '';
if ($model->phone_number) {
$phone = $model->ext.' '.$model->phone_number;
}
$mobile = '';
if ($model->mobile) {
$mobile = $model->mobile;
}
$phone = $phone.'&nbsp;&nbsp;&nbsp;'.$mobile;
return $phone;
})
/* column account status */
->addColumn('status', function ($model) {
$status = $model->active;
if ($status == 1) {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
} else {
$stat = '<button class="btn btn-danger btn-xs">Inactive</button>';
}
return $stat;
})
/* column ban status */
->addColumn('ban', function ($model) {
$status = $model->ban;
if ($status == 1) {
$stat = '<button class="btn btn-danger btn-xs">Banned</button>';
} else {
$stat = '<button class="btn btn-success btn-xs">Active</button>';
}
return $stat;
})
/* column last login date */
->addColumn('lastlogin', function ($model) {
$t = $model->updated_at;
return TicketController::usertimezone($t);
})
/* column actions */
->addColumn('Actions', function ($model) {
return '<a href="'.route('user.edit', $model->id).'" class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp; <a href="'.route('user.show', $model->id).'" class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>';
})
->make();
}
/**
* Show the form for creating a new users.
*
* @return type view
*/
public function create()
{
try {
return view('themes.default1.agent.helpdesk.user.create');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* Store a newly created users in storage.
*
* @param type User $user
* @param type Sys_userRequest $request
*
* @return type redirect
*/
public function store(User $user, Sys_userRequest $request)
{
/* insert the input request to sys_user table */
/* Check whether function success or not */
$user->email = $request->input('email');
$user->user_name = $request->input('full_name');
$user->mobile = $request->input('mobile');
$user->ext = $request->input('ext');
$user->phone_number = $request->input('phone_number');
$user->active = $request->input('active');
$user->internal_note = $request->input('internal_note');
$user->role = 'user';
try {
$user->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Created Successfully');
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect('user')->with('fails', $e->errorInfo[2]);
}
}
/**
* Display the specified users.
*
* @param type int $id
* @param type User $user
*
* @return type view
*/
public function show($id, User $user)
{
try {
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
return view('themes.default1.agent.helpdesk.user.show', compact('users'));
} catch (Exception $e) {
return view('404');
}
}
/**
* Show the form for editing the specified resource.
*
* @param type int $id
* @param type User $user
*
* @return type Response
*/
public function edit($id, User $user)
{
try {
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
return view('themes.default1.agent.helpdesk.user.edit', compact('users'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* Update the specified user in storage.
*
* @param type int $id
* @param type User $user
* @param type Sys_userUpdate $request
*
* @return type Response
*/
public function update($id, User $user, Sys_userUpdate $request)
{
/* select the field where id = $id(request Id) */
$users = $user->whereId($id)->first();
/* Update the value by selected field */
/* Check whether function success or not */
try {
$users->fill($request->input())->save();
/* redirect to Index page with Success Message */
return redirect('user')->with('success', 'User Updated Successfully');
} catch (Exception $e) {
/* redirect to Index page with Fails Message */
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* get agent profile page.
*
* @return type view
*/
public function getProfile()
{
$user = Auth::user();
try {
return view('themes.default1.agent.helpdesk.user.profile', compact('user'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* get profile edit page.
*
* @return type view
*/
public function getProfileedit()
{
$user = Auth::user();
try {
return view('themes.default1.agent.helpdesk.user.profile-edit', compact('user'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* post profile edit.
*
* @param type int $id
* @param type ProfileRequest $request
*
* @return type Redirect
*/
public function postProfileedit(ProfileRequest $request)
{
// geet authenticated user details
$user = Auth::user();
$user->gender = $request->input('gender');
$user->save();
// checking availability of agent profile ppicture
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
$destinationPath = 'lb-faveo/media/profilepic';
$user->profile_pic = $name;
} elseif ($request->input('gender') == 0) {
$name = 'avatar2.png';
$destinationPath = 'lb-faveo/media/profilepic';
$user->profile_pic = $name;
}
}
// checking if the post system includes agent profile picture upload
if (Input::file('profile_pic')) {
// fetching picture name
$name = Input::file('profile_pic')->getClientOriginalName();
// fetching upload destination path
$destinationPath = 'lb-faveo/media/profilepic';
// adding a random value to profile picture filename
$fileName = rand(0000, 9999).'.'.$name;
// moving the picture to a destination folder
Input::file('profile_pic')->move($destinationPath, $fileName);
// saving filename to database
$user->profile_pic = $fileName;
} else {
try {
$user->fill($request->except('profile_pic', 'gender'))->save();
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
} catch (Exception $e) {
return Redirect::route('profile')->with('success', $e->errorInfo[2]);
}
}
if ($user->fill($request->except('profile_pic'))->save()) {
return Redirect::route('profile')->with('success', 'Profile Updated sucessfully');
}
}
/**
* Post profile password.
*
* @param type int $id
* @param type ProfilePassword $request
*
* @return type Redirect
*/
public function postProfilePassword($id, ProfilePassword $request)
{
// get authenticated user
$user = Auth::user();
// checking if the old password matches the new password
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
$user->password = Hash::make($request->input('new_password'));
try {
$user->save();
return redirect('profile-edit')->with('success1', 'Password Updated sucessfully');
} catch (Exception $e) {
return redirect('profile-edit')->with('fails', $e->errorInfo[2]);
}
} else {
return redirect('profile-edit')->with('fails1', 'Password was not Updated. Incorrect old password');
}
}
/**
* Assigning an user to an organization.
*
* @param type $id
*
* @return type boolean
*/
public function UserAssignOrg($id)
{
$org = Input::get('org');
$user_org = new User_org();
$user_org->org_id = $org;
$user_org->user_id = $id;
$user_org->save();
return 1;
}
/**
* creating an organization in user profile page via modal popup.
*
* @param type $id
*
* @return type
*/
public function User_Create_Org($id)
{
// checking if the entered value for website is available in database
if (Input::get('website') != null) {
// checking website
$check = Organization::where('website', '=', Input::get('website'))->first();
} else {
$check = null;
}
// checking if the name is unique
$check2 = Organization::where('name', '=', Input::get('name'))->first();
// if any of the fields is not available then return false
if (\Input::get('name') == null) {
return 'Name is required';
} elseif ($check2 != null) {
return 'Name should be Unique';
} elseif ($check != null) {
return 'Website should be Unique';
} else {
// storing organization details and assigning the current user to that organization
$org = new Organization();
$org->name = Input::get('name');
$org->phone = Input::get('phone');
$org->website = Input::get('website');
$org->address = Input::get('address');
$org->internal_notes = Input::get('internal');
$org->save();
$user_org = new User_org();
$user_org->org_id = $org->id;
$user_org->user_id = $id;
$user_org->save();
// for success return 0
return 0;
}
}
}

View File

@@ -63,23 +63,18 @@ class ArticleController extends Controller
public function getData()
{
$article = new Article();
$articles = $article
->select('id', 'name', 'description', 'publish_time', 'slug')
->orderBy('publish_time','desc')
->get();
// returns chumper datatable
return Datatable::query($article)
/* searcable column name */
->searchColumns('name')
/* order column name and description */
->orderColumns('name', 'description')
return Datatable::Collection($articles)
/* add column name */
->addColumn('name', function ($model) {
$string = strip_tags($model->name);
if (strlen($string) > 40) {
// truncate string
$stringCut = substr($string, 0, 40);
} else {
$stringCut = $model->name;
}
$name = str_limit($model->name, 20, '...');
return $stringCut.'...';
return "<p title=$model->name>$name</p>";
})
/* add column Created */
->addColumn('publish_time', function ($model) {
@@ -90,7 +85,7 @@ class ArticleController extends Controller
/* add column action */
->addColumn('Actions', function ($model) {
/* here are all the action buttons and modal popup to delete articles with confirmations */
return '<span data-toggle="modal" data-target="#deletearticle'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').' </button></span>&nbsp;<a href=article/'.$model->id.'/edit class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href=show/'.$model->slug.' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
return '<span data-toggle="modal" data-target="#deletearticle'.$model->id.'"><a href="#" ><button class="btn btn-danger btn-xs"></a> '.\Lang::get('lang.delete').' </button></span>&nbsp;<a href='.url("article/$model->id/edit").' class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a>&nbsp;<a href='.url("show/$model->slug").' class="btn btn-primary btn-xs">'.\Lang::get('lang.view').'</a>
<div class="modal fade" id="deletearticle'.$model->id.'">
<div class="modal-dialog">
<div class="modal-content">
@@ -103,12 +98,14 @@ class ArticleController extends Controller
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
<a href="article/delete/'.$model->slug.'"><button class="btn btn-danger">delete</button></a>
<a href='.url("article/delete/$model->slug").'><button class="btn btn-danger">delete</button></a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</div>
</div>';
})
->searchColumns('name', 'description', 'publish_time')
->orderColumns('name', 'description', 'publish_time')
->make();
}
@@ -253,9 +250,9 @@ class ArticleController extends Controller
$article->publish_time = $publishTime;
$article->save();
return redirect('article')->with('success', Lang::get('lang.article_updated_successfully'));
return redirect()->back()->with('success', Lang::get('lang.article_updated_successfully'));
} catch (Exception $e) {
return redirect('article')->with('fails', Lang::get('lang.article_not_updated').'<li>'.$e->getMessage().'</li>');
return redirect()->back()->with('fails', Lang::get('lang.article_not_updated').'<li>'.$e->getMessage().'</li>');
}
}
@@ -285,12 +282,12 @@ class ArticleController extends Controller
}
if ($article) {
if ($article->delete()) {//true:redirect to index page with success message
return Redirect::back()->with('success', Lang::get('lang.article_deleted_successfully'));
return redirect('article')->with('success', Lang::get('lang.article_deleted_successfully'));
} else { //redirect to index page with fails message
return Redirect::back()->with('fails', Lang::get('lang.article_not_deleted'));
return redirect('article')->with('fails', Lang::get('lang.article_not_deleted'));
}
} else {
return Redirect::back()->with('fails', Lang::get('lang.article_can_not_deleted'));
return redirect('article')->with('fails', Lang::get('lang.article_can_not_deleted'));
}
}

View File

@@ -77,14 +77,7 @@ class CategoryController extends Controller
/* add column name */
->addColumn('name', function ($model) {
$string = strip_tags($model->name);
if (strlen($string) > 40) {
// truncate string
$stringCut = substr($string, 0, 40);
} else {
$stringCut = $model->name;
}
return $stringCut.'...';
return str_limit($string, 20);
})
/* add column Created */
->addColumn('Created', function ($model) {
@@ -127,7 +120,7 @@ class CategoryController extends Controller
public function create(Category $category)
{
/* Get the all attributes in the category model */
$category = $category->get();
$category = $category->lists('name','id')->toArray();
/* get the view page to create new category with all attributes
of category model */
try {
@@ -148,13 +141,12 @@ class CategoryController extends Controller
public function store(Category $category, CategoryRequest $request)
{
/* Get the whole request from the form and insert into table via model */
$sl = $request->input('slug');
$sl = $request->input('name');
$slug = str_slug($sl, '-');
$category->slug = $slug;
// send success message to index page
try {
$category->fill($request->except('slug'))->save();
$category->fill($request->input())->save();
return Redirect::back()->with('success', Lang::get('lang.category_inserted_successfully'));
} catch (Exception $e) {
return Redirect::back()->with('fails', Lang::get('lang.category_not_inserted').'<li>'.$e->getMessage().'</li>');
@@ -169,15 +161,13 @@ class CategoryController extends Controller
*
* @return type view
*/
public function edit($slug)
public function edit($id)
{
// fetch the category
$cid = Category::where('id', $slug)->first();
$id = $cid->id;
/* get the atributes of the category model whose id == $id */
$category = Category::whereId($id)->first();
$categories = Category::lists('name','id')->toArray();
/* get the Edit page the selected category via id */
return view('themes.default1.agent.kb.category.edit', compact('category'));
return view('themes.default1.agent.kb.category.edit', compact('category','categories'));
}
/**
@@ -189,22 +179,18 @@ class CategoryController extends Controller
*
* @return type redirect
*/
public function update($slug, CategoryUpdate $request)
public function update($id, CategoryRequest $request)
{
/* Edit the selected category via id */
$category = Category::where('id', $slug)->first();
$sl = $request->input('slug');
$category = Category::where('id', $id)->first();
$sl = $request->input('name');
$slug = str_slug($sl, '-');
// dd($slug);
$category->slug = $slug;
/* update the values at the table via model according with the request */
//redirct to index page with success message
try {
$category->fill($request->all())->save();
$category->slug = $slug;
$category->save();
$category->fill($request->input())->save();
return redirect('category')->with('success', Lang::get('lang.category_updated_successfully'));
} catch (Exception $e) {
//redirect to index with fails message

View File

@@ -125,11 +125,11 @@ class PageController extends Controller
*/
public function store(PageRequest $request)
{
$sl = $request->input('slug');
$sl = $request->input('name');
$slug = str_slug($sl, '-');
$this->page->slug = $slug;
try {
$this->page->fill($request->except('slug'))->save();
$this->page->fill($request->input())->save();
return redirect('page')->with('success', Lang::get('lang.page_created_successfully'));
} catch (Exception $e) {
@@ -163,13 +163,12 @@ class PageController extends Controller
*
* @return type redirect
*/
public function update($slug, PageUpdate $request)
public function update($slug, PageRequest $request)
{
// get pages with respect to slug
$pages = $this->page->where('slug', $slug)->first();
$sl = $request->input('slug');
$sl = $request->input('name');
$slug = str_slug($sl, '-');
$this->page->slug = $slug;
try {
$pages->fill($request->all())->save();
$pages->slug = $slug;

Binary file not shown.

View File

@@ -33,8 +33,8 @@ use Illuminate\Support\Collection;
*
* @version v1
*/
class ApiController extends Controller
{
class ApiController extends Controller {
public $user;
public $request;
public $ticket;
@@ -54,8 +54,7 @@ class ApiController extends Controller
/**
* @param Request $request
*/
public function __construct(Request $request)
{
public function __construct(Request $request) {
$this->request = $request;
$this->middleware('jwt.auth');
@@ -64,7 +63,9 @@ class ApiController extends Controller
$user = \JWTAuth::parseToken()->authenticate();
$this->user = $user;
} catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
} catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
}
$ticket = new TicketController();
@@ -119,17 +120,16 @@ class ApiController extends Controller
*
* @return json
*/
public function createTicket()
{
public function createTicket() {
try {
$v = \Validator::make($this->request->all(), [
'user_id' => 'required|exists:users,id',
'subject' => 'required',
'body' => 'required',
'user_id' => 'required|exists:users,id',
'subject' => 'required',
'body' => 'required',
'helptopic' => 'required|exists:help_topic,id',
'sla' => 'required|exists:sla_plan,id',
'priority' => 'required|exists:ticket_priority,priority_id',
'dept' => 'required|exists:department,id',
'sla' => 'required|exists:sla_plan,id',
'priority' => 'required|exists:ticket_priority,priority_id',
'dept' => 'required|exists:department,id',
]);
if ($v->fails()) {
$error = $v->errors();
@@ -178,7 +178,7 @@ class ApiController extends Controller
$error = $e->getMessage();
return response()->json(compact('error'))
->header('Authenticate: xBasic realm', 'fake');
->header('Authenticate: xBasic realm', 'fake');
}
}
@@ -189,12 +189,11 @@ class ApiController extends Controller
*
* @return json
*/
public function ticketReply()
{
public function ticketReply() {
//dd($this->request->all());
try {
$v = \Validator::make($this->request->all(), [
'ticket_ID' => 'required|exists:tickets,id',
'ticket_ID' => 'required|exists:tickets,id',
'reply_content' => 'required',
]);
if ($v->fails()) {
@@ -224,15 +223,14 @@ class ApiController extends Controller
*
* @return json
*/
public function editTicket()
{
public function editTicket() {
try {
$v = \Validator::make($this->request->all(), [
'ticket_id' => 'required|exists:tickets,id',
'subject' => 'required',
'sla_plan' => 'required|exists:sla_plan,id',
'help_topic' => 'required|exists:help_topic,id',
'ticket_source' => 'required|exists:ticket_source,id',
'ticket_id' => 'required|exists:tickets,id',
'subject' => 'required',
'sla_plan' => 'required|exists:sla_plan,id',
'help_topic' => 'required|exists:help_topic,id',
'ticket_source' => 'required|exists:ticket_source,id',
'ticket_priority' => 'required|exists:ticket_priority,priority_id',
]);
if ($v->fails()) {
@@ -262,8 +260,7 @@ class ApiController extends Controller
*
* @return json
*/
public function deleteTicket()
{
public function deleteTicket() {
try {
$v = \Validator::make($this->request->all(), [
'ticket_id' => 'required|exists:tickets,id',
@@ -296,16 +293,15 @@ class ApiController extends Controller
*
* @return json
*/
public function openedTickets()
{
public function openedTickets() {
try {
// $result = $this->model->where('status', '=', 1)->where('isanswered', '=', 0)->where('assigned_to', '=', null)->orderBy('id', 'DESC')->get();
// return response()->json(compact('result'));
$result = $this->user->join('tickets', function ($join) {
$join->on('users.id', '=', 'tickets.user_id')
$join->on('users.id', '=', 'tickets.user_id')
->where('isanswered', '=', 0)->where('status', '=', 1)->whereNull('assigned_to');
})
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -341,16 +337,15 @@ class ApiController extends Controller
*
* @return json
*/
public function unassignedTickets()
{
public function unassignedTickets() {
try {
//dd('sdhjbc');
// $result = $this->model->where('assigned_to', '=', null)->where('status', '1')->orderBy('id', 'DESC')->get();
// return response()->json(compact('result'));
$unassigned = $this->user->join('tickets', function ($join) {
$join->on('users.id', '=', 'tickets.user_id')
$join->on('users.id', '=', 'tickets.user_id')
->whereNull('assigned_to')->where('status', '=', 1);
})
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -360,8 +355,8 @@ class ApiController extends Controller
$join->on('tickets.id', '=', 'ticket_thread.ticket_id')
->whereNotNull('title');
})
->select('user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('ticket_thread.updated_at', 'desc')
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'),'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('updated_at', 'desc')
->groupby('tickets.id')
->distinct()
->paginate(10)
@@ -386,16 +381,15 @@ class ApiController extends Controller
*
* @return json
*/
public function closeTickets()
{
public function closeTickets() {
try {
// $result = $this->model->where('status', '>', 1)->where('status', '<', 4)->orderBy('id', 'DESC')->get();
// return response()->json(compact('result'));
$result = $this->user->join('tickets', function ($join) {
$join->on('users.id', '=', 'tickets.user_id')
->where('isanswered', '=', 0)->where('status', '>', 1)->where('status', '<', 4);
})
$join->on('users.id', '=', 'tickets.user_id')
->where('status','=',3)->orWhere('status','=',2);
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -405,8 +399,8 @@ class ApiController extends Controller
$join->on('tickets.id', '=', 'ticket_thread.ticket_id')
->whereNotNull('title');
})
->select('user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('ticket_thread.updated_at', 'desc')
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'),'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('updated_at', 'desc')
->groupby('tickets.id')
->distinct()
->paginate(10)
@@ -431,8 +425,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getAgents()
{
public function getAgents() {
try {
$result = $this->faveoUser->where('role', 'agent')->orWhere('role', 'admin')->where('active', 1)->get();
@@ -455,8 +448,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getTeams()
{
public function getTeams() {
try {
$result = $this->team->get();
@@ -479,12 +471,11 @@ class ApiController extends Controller
*
* @return json
*/
public function assignTicket()
{
public function assignTicket() {
try {
$v = \Validator::make($this->request->all(), [
'ticket_id' => 'required',
'user' => 'required',
'user' => 'required',
]);
if ($v->fails()) {
$error = $v->errors();
@@ -518,8 +509,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getCustomers()
{
public function getCustomers() {
try {
$v = \Validator::make($this->request->all(), [
'search' => 'required',
@@ -530,10 +520,10 @@ class ApiController extends Controller
return response()->json(compact('error'));
}
$search = $this->request->input('search');
$result = $this->faveoUser->where('first_name', 'like', '%'.$search.'%')->orWhere('last_name', 'like', '%'.$search.'%')->orWhere('user_name', 'like', '%'.$search.'%')->orWhere('email', 'like', '%'.$search.'%')->get();
$result = $this->faveoUser->where('first_name', 'like', '%' . $search . '%')->orWhere('last_name', 'like', '%' . $search . '%')->orWhere('user_name', 'like', '%' . $search . '%')->orWhere('email', 'like', '%' . $search . '%')->get();
return response()->json(compact('result'))
->header('X-Header-One', 'Header Value');
->header('X-Header-One', 'Header Value');
} catch (Exception $e) {
$error = $e->getMessage();
$line = $e->getLine();
@@ -544,8 +534,7 @@ class ApiController extends Controller
$error = $e->getMessage();
return response()->json(compact('error'))
->header('X-Header-One', 'Header Value');
->header('X-Header-One', 'Header Value');
}
}
@@ -554,8 +543,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getCustomersWith()
{
public function getCustomersWith() {
try {
$users = $this->user
->leftJoin('user_assign_organization', 'user_assign_organization.user_id', '=', 'users.id')
@@ -577,7 +565,7 @@ class ApiController extends Controller
$error = $e->getMessage();
return response()->json(compact('error'))
->header('Authenticate: xBasic realm', 'fake');
->header('Authenticate: xBasic realm', 'fake');
}
}
@@ -586,8 +574,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getCustomer()
{
public function getCustomer() {
try {
$v = \Validator::make($this->request->all(), [
'user_id' => 'required',
@@ -619,8 +606,7 @@ class ApiController extends Controller
*
* @return json
*/
public function searchTicket()
{
public function searchTicket() {
try {
$v = \Validator::make($this->request->all(), [
'search' => 'required',
@@ -631,7 +617,7 @@ class ApiController extends Controller
return response()->json(compact('error'));
}
$search = $this->request->input('search');
$result = $this->thread->select('ticket_id')->where('title', 'like', '%'.$search.'%')->orWhere('body', 'like', '%'.$search.'%')->get();
$result = $this->thread->select('ticket_id')->where('title', 'like', '%' . $search . '%')->orWhere('body', 'like', '%' . $search . '%')->get();
return response()->json(compact('result'));
} catch (Exception $e) {
@@ -652,8 +638,7 @@ class ApiController extends Controller
*
* @return json
*/
public function ticketThreads()
{
public function ticketThreads() {
try {
$v = \Validator::make($this->request->all(), [
'id' => 'required',
@@ -690,8 +675,7 @@ class ApiController extends Controller
*
* @return json
*/
public function checkUrl()
{
public function checkUrl() {
//dd($this->request);
try {
$v = \Validator::make($this->request->all(), [
@@ -708,7 +692,7 @@ class ApiController extends Controller
$url = str_finish($url, '/');
}
$url = $url.'/api/v1/helpdesk/check-url?api_key='.$this->request->input('api_key').'&token='.\Config::get('app.token');
$url = $url . '/api/v1/helpdesk/check-url?api_key=' . $this->request->input('api_key') . '&token=' . \Config::get('app.token');
$result = $this->CallGetApi($url);
//dd($result);
return response()->json(compact('result'));
@@ -728,8 +712,7 @@ class ApiController extends Controller
*
* @return string
*/
public function urlResult()
{
public function urlResult() {
return 'success';
}
@@ -740,8 +723,7 @@ class ApiController extends Controller
*
* @return type int|string|json
*/
public function callGetApi($url)
{
public function callGetApi($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
@@ -750,7 +732,7 @@ class ApiController extends Controller
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo 'error:'.curl_error($curl);
echo 'error:' . curl_error($curl);
}
return $response;
@@ -765,8 +747,7 @@ class ApiController extends Controller
*
* @return type int|string|json
*/
public function callPostApi($url, $data)
{
public function callPostApi($url, $data) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
@@ -776,7 +757,7 @@ class ApiController extends Controller
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo 'error:'.curl_error($curl);
echo 'error:' . curl_error($curl);
}
return $response;
@@ -788,8 +769,7 @@ class ApiController extends Controller
*
* @return type | json
*/
public function generateApiKey()
{
public function generateApiKey() {
try {
$set = $this->setting->where('id', '1')->first();
//dd($set);
@@ -823,8 +803,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getHelpTopic()
{
public function getHelpTopic() {
try {
$result = $this->helptopic->get();
@@ -847,8 +826,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getSlaPlan()
{
public function getSlaPlan() {
try {
$result = $this->slaPlan->get();
@@ -871,8 +849,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getPriority()
{
public function getPriority() {
try {
$result = $this->priority->get();
@@ -895,8 +872,7 @@ class ApiController extends Controller
*
* @return json
*/
public function getDepartment()
{
public function getDepartment() {
try {
$result = $this->department->get();
@@ -919,8 +895,7 @@ class ApiController extends Controller
*
* @return type json
*/
public function getTickets()
{
public function getTickets() {
try {
$tickets = $this->model->orderBy('created_at', 'desc')->paginate(10);
$tickets->toJson();
@@ -944,10 +919,13 @@ class ApiController extends Controller
*
* @return type json
*/
public function inbox()
{
public function inbox() {
try {
$inbox = $this->user->join('tickets', 'users.id', '=', 'tickets.user_id')
$inbox = $this->user->join('tickets', function ($join) {
$join->on('users.id', '=', 'tickets.user_id')
->where('status', '=', 1);
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -955,10 +933,10 @@ class ApiController extends Controller
->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
->join('ticket_thread', function ($join) {
$join->on('tickets.id', '=', 'ticket_thread.ticket_id')
->whereNotNull('title');
->whereNotNull('ticket_thread.title');
})
->select('user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('ticket_thread.updated_at', 'desc')
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'),'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'ticket_thread.title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('updated_at', 'desc')
->groupby('tickets.id')
->distinct()
->paginate(10)
@@ -983,13 +961,12 @@ class ApiController extends Controller
*
* @return type json
*/
public function internalNote()
{
public function internalNote() {
try {
$v = \Validator::make($this->request->all(), [
'userid' => 'required|exists:users,id',
'userid' => 'required|exists:users,id',
'ticketid' => 'required|exists:tickets,id',
'body' => 'required',
'body' => 'required',
]);
if ($v->fails()) {
$error = $v->errors();
@@ -1016,13 +993,12 @@ class ApiController extends Controller
}
}
public function getTrash()
{
public function getTrash() {
try {
$trash = $this->user->join('tickets', function ($join) {
$join->on('users.id', '=', 'tickets.user_id')
$join->on('users.id', '=', 'tickets.user_id')
->where('status', '=', 5);
})
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -1032,8 +1008,8 @@ class ApiController extends Controller
$join->on('tickets.id', '=', 'ticket_thread.ticket_id')
->whereNotNull('title');
})
->select('user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('ticket_thread.updated_at', 'desc')
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'),'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('updated_at', 'desc')
->groupby('tickets.id')
->distinct()
->paginate(10)
@@ -1053,8 +1029,7 @@ class ApiController extends Controller
}
}
public function getMyTicketsAgent()
{
public function getMyTicketsAgent() {
try {
$v = \Validator::make($this->request->all(), [
'user_id' => 'required|exists:users,id',
@@ -1071,9 +1046,10 @@ class ApiController extends Controller
return response()->json(compact('error'));
}
$result = $this->user->join('tickets', function ($join) use ($id) {
$join->on('users.id', '=', 'tickets.assigned_to')
->where('user_id', '=', $id);
})
$join->on('users.id', '=', 'tickets.assigned_to')
->where('status', '=', 1);
//->where('user_id', '=', $id);
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -1083,8 +1059,9 @@ class ApiController extends Controller
$join->on('tickets.id', '=', 'ticket_thread.ticket_id')
->whereNotNull('title');
})
->select('user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('ticket_thread.updated_at', 'desc')
->where('users.id',$id)
->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'),'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
->orderBy('updated_at', 'desc')
->groupby('tickets.id')
->distinct()
->paginate(10)
@@ -1104,8 +1081,7 @@ class ApiController extends Controller
}
}
public function getMyTicketsUser()
{
public function getMyTicketsUser() {
try {
$v = \Validator::make($this->request->all(), [
'user_id' => 'required|exists:users,id',
@@ -1122,9 +1098,9 @@ class ApiController extends Controller
return response()->json(compact('error'));
}
$result = $this->user->join('tickets', function ($join) use ($id) {
$join->on('users.id', '=', 'tickets.user_id')
$join->on('users.id', '=', 'tickets.user_id')
->where('user_id', '=', $id);
})
})
->join('department', 'department.id', '=', 'tickets.dept_id')
->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
@@ -1139,7 +1115,7 @@ class ApiController extends Controller
->groupby('tickets.id')
->distinct()
->get()
// ->paginate(10)
// ->paginate(10)
->toJson();
return $result;
@@ -1156,8 +1132,7 @@ class ApiController extends Controller
}
}
public function getTicketById()
{
public function getTicketById() {
try {
$v = \Validator::make($this->request->all(), [
'id' => 'required|exists:tickets,id',
@@ -1169,11 +1144,18 @@ class ApiController extends Controller
}
$id = $this->request->input('id');
if (!$this->model->where('id', $id)->first()) {
$error = 'There is no Ticket as ticket id: '.$id;
$error = 'There is no Ticket as ticket id: ' . $id;
return response()->json(compact('error'));
}
$result = $this->model->where('id', $id)->first();
$query = $this->user->join('tickets', function ($join) use ($id) {
$join->on('users.id', '=', 'tickets.user_id')
->where('tickets.id', '=', $id);
});
$response = $this->differenciateHelpTopic($query);
//$select = 'users.email','users.user_name','users.first_name','users.last_name','tickets.id','ticket_number','num_sequence','user_id','priority_id','sla','max_open_ticket','captcha','status','lock_by','lock_at','source','isoverdue','reopened','isanswered','is_deleted', 'closed','is_transfer','transfer_at','reopened_at','duedate','closed_at','last_message_at','last_response_at';
$result = $response->addSelect('users.email','users.user_name','users.first_name','users.last_name','tickets.id','ticket_number','user_id','priority_id','sla','status','lock_by','lock_at','source','isoverdue','reopened','isanswered','is_deleted', 'closed','reopened_at','duedate','closed_at','last_message_at','last_response_at','tickets.created_at','tickets.updated_at')->first();
return response()->json(compact('result'));
} catch (\Exception $e) {
@@ -1189,8 +1171,7 @@ class ApiController extends Controller
}
}
public function createPagination($array, $perPage)
{
public function createPagination($array, $perPage) {
try {
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
@@ -1218,8 +1199,7 @@ class ApiController extends Controller
}
}
public function collaboratorSearch()
{
public function collaboratorSearch() {
$this->validate($this->request, ['term' => 'required']);
try {
$emails = $this->ticket->autosearch();
@@ -1229,7 +1209,7 @@ class ApiController extends Controller
foreach ($emails as $key => $email) {
$user_model = $user->where('email', $email)->first();
//return $user_model;
$users[$key]['name'] = $user_model->first_name.' '.$user_model->last_name;
$users[$key]['name'] = $user_model->first_name . ' ' . $user_model->last_name;
$users[$key]['email'] = $email;
$users[$key]['avatar'] = $this->avatarUrl($email);
}
@@ -1246,13 +1226,12 @@ class ApiController extends Controller
}
}
public function avatarUrl($email)
{
public function avatarUrl($email) {
try {
$user = new User();
$user = $user->where('email', $email)->first();
if ($user->profile_pic) {
$url = url('lb-faveo/media/profilepic/'.$user->profile_pic);
$url = url('uploads/profilepic/' . $user->profile_pic);
} else {
$url = \Gravatar::src($email);
}
@@ -1264,11 +1243,10 @@ class ApiController extends Controller
}
}
public function addCollaboratorForTicket()
{
public function addCollaboratorForTicket() {
try {
$v = \Validator::make(\Input::get(), [
'email' => 'required|email|unique:users',
'email' => 'required|email|unique:users',
'ticket_id' => 'required',
]
);
@@ -1295,8 +1273,7 @@ class ApiController extends Controller
}
}
public function getCollaboratorForTicket()
{
public function getCollaboratorForTicket() {
try {
$v = \Validator::make(\Input::get(), [
'ticket_id' => 'required',
@@ -1325,12 +1302,11 @@ class ApiController extends Controller
}
}
public function deleteCollaborator()
{
public function deleteCollaborator() {
try {
$v = \Validator::make(\Input::get(), [
'ticketid' => 'required',
'email' => 'required',
'email' => 'required',
]
);
if ($v->fails()) {
@@ -1350,8 +1326,7 @@ class ApiController extends Controller
}
}
public function dependency()
{
public function dependency() {
try {
$department = $this->department->select('name', 'id')->get()->toArray();
$sla = $this->slaPlan->select('name', 'id')->get()->toArray();
@@ -1362,7 +1337,7 @@ class ApiController extends Controller
$status = \DB::table('ticket_status')->select('name', 'id')->get();
$source = \DB::table('ticket_source')->select('name', 'id')->get();
$result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team,
'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source, ];
'priorities' => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source,];
return response()->json(compact('result'));
} catch (\Exception $e) {
@@ -1373,4 +1348,73 @@ class ApiController extends Controller
return response()->json(compact('error', 'file', 'line'));
}
}
public function differenciateHelpTopic($query){
$ticket = $query->first();
$check = 'department';
if($ticket){
if($ticket->dept_id && $ticket->help_topic_id){
return $this->getSystem($check, $query);
}
if(!$ticket->dept_id && $ticket->help_topic_id){
return $query->select('tickets.help_topic_id');
}
if($ticket->dept_id && !$ticket->help_topic_id){
return $query->select('tickets.dept_id');
}
}
}
public function getSystem($check,$query){
switch ($check){
case 'department':
return $query->select('tickets.dept_id');
case 'helpTopic':
return $query->select('tickets.help_topic_id');
default :
return $query->select('tickets.dept_id');
}
}
/**
* Register a user with username and password.
*
* @param Request $request
*
* @return type json
*/
public function register(Request $request)
{
try {
$v = \Validator::make($request->all(), [
'email' => 'required|email|unique:users',
'password' => 'required|min:6',
]);
if ($v->fails()) {
$error = $v->errors();
return response()->json(compact('error'));
}
$auth = $this->user;
$email = $request->input('email');
$username = $request->input('email');
$password = \Hash::make($request->input('password'));
$role = $request->input('role');
if($auth->role=='agent'){
$role = "user";
}
$user = new User();
$user->password = $password;
$user->user_name = $username;
$user->email = $email;
$user->role = $role;
$user->save();
return response()->json(compact('user'));
} catch (\Exception $e) {
$error = $e->getMessage();
return response()->json(compact('error'));
}
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace App\Http\Controllers\Api\v1;
// Controllers
use App\Http\Controllers\Controller;
// Requests
use Illuminate\Http\Request;
// Models
use App\User;
use App\Model\helpdesk\Ticket\Tickets;
use App\Model\helpdesk\Ticket\Ticket_Thread;
// classes
use LaravelFCM\Message\PayloadNotificationBuilder;
use LaravelFCM\Message\Topics;
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Response\DownstreamResponse;
use FCM;
use FCMGroup;
/**
* **********************************************
* PushNotificationController
* **********************************************
* This controller is used to send notification to FCM cloud which later will
* foreward notification to Mobile Application
*
* @author Ladybird <info@ladybirdweb.com>
*/
class PushNotificationController extends Controller {
public function Response($token, $body, $ticket_id = null) {
$optionBuiler = new OptionsBuilder();
$optionBuiler->setTimeToLive(60 * 60);
$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder->setBody($body)
->setSound('default')
->setIcon('ic_stat_f1')
->setClickAction('OPEN_ACTIVITY_1');
if($ticket_id != null) {
$ticket_data = Tickets::where('id', '=', $ticket_id )->first();
$thread_data = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first();
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['ticket_id' => $ticket_id]);
$dataBuilder->addData(['ticket_number' => $ticket_data->ticket_number]);
$dataBuilder->addData(['ticket_opened_by' => $ticket_data->user_id]);
$dataBuilder->addData(['ticket_subject' => $thread_data->title]);
}
$option = $optionBuiler->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$tokens = $token;
$downstreamResponse = FCM::sendTo($tokens, $option, $notification, $data);
// $downstreamResponse = new DownstreamResponse($response, $tokens);
// dd($downstreamResponse);
$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();
// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();
// return Array (key : oldToken, value : new token - you must change the token in your database )
$downstreamResponse->tokensToModify();
// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
// return Array (key:token, value:errror) - in production you should remove from your database the tokens
}
/**
* function to get the fcm token from the api under a user.
* @param \Illuminate\Http\Request $request
* @return type
*/
public function fcmToken(Request $request, User $user) {
// get the requested details
$user_id = $request->input('user_id');
$fcm_token = $request->input('fcm_token');
// check for all the valid details
if($user_id != null && $user_id != "" && $fcm_token != null && $fcm_token != "") {
// search the user_id in database
$user = $user->where('id', '=', $user_id)->first();
if($user != null) {
$user->fcm_token = $fcm_token;
$user->save();
// success response for success case
return ['response' => 'success'];
} else {
// failure respunse for invalid user_id in the system
return ['response' => 'fail', 'reason' => 'Invalid user_id'];
}
} else {
// failure respunse for invalid input credentials
return ['response' => 'fail', 'reason' => 'Invalid Credentials'];
}
}
}

View File

@@ -422,6 +422,7 @@ class TicketController extends Controller
$ticket->help_topic_id = Input::get('help_topic');
$ticket->source = Input::get('ticket_source');
$ticket->priority_id = Input::get('ticket_priority');
$ticket->status = Input::get('status');
$ticket->save();
$threads = $thread->where('ticket_id', '=', $ticket_id)->first();
@@ -724,7 +725,7 @@ class TicketController extends Controller
$user = new User();
$user = $user->where('email', $email)->first();
if ($user->profile_pic) {
$url = url('lb-faveo/media/profilepic/'.$user->profile_pic);
$url = url('uploads/profilepic/'.$user->profile_pic);
} else {
$url = \Gravatar::src($email);
}

View File

@@ -50,7 +50,7 @@ class TokenAuthController extends Controller
//$credentials = $request->only('email', 'password');
try {
if (!$token = JWTAuth::attempt([$field => $usernameinput, 'password' => $password])) {
if (!$token = JWTAuth::attempt([$field => $usernameinput, 'password' => $password,'active'=>1])) {
return response()->json(['error' => 'invalid_credentials', 'status_code' => 401]);
}
} catch (JWTException $e) {
@@ -100,30 +100,30 @@ class TokenAuthController extends Controller
*
* @return type json
*/
public function register(Request $request)
{
try {
$v = \Validator::make($request->all(), [
'email' => 'required|email|unique:users',
'password' => 'required',
]);
if ($v->fails()) {
$error = $v->errors();
return response()->json(compact('error'));
}
$newuser = $request->all();
$password = Hash::make($request->input('password'));
$newuser['password'] = $password;
return User::create($newuser);
} catch (\Exception $e) {
$error = $e->getMessage();
return response()->json(compact('error'));
}
}
// public function register(Request $request)
// {
// try {
// $v = \Validator::make($request->all(), [
// 'email' => 'required|email|unique:users',
// 'password' => 'required',
// ]);
// if ($v->fails()) {
// $error = $v->errors();
//
// return response()->json(compact('error'));
// }
// $newuser = $request->all();
// $password = Hash::make($request->input('password'));
//
// $newuser['password'] = $password;
//
// return User::create($newuser);
// } catch (\Exception $e) {
// $error = $e->getMessage();
//
// return response()->json(compact('error'));
// }
// }
/**
* verify the url is existing or not.

View File

@@ -53,7 +53,6 @@ class AuthController extends Controller
public function __construct(PhpMailController $PhpMailController)
{
$this->PhpMailController = $PhpMailController;
SettingsController::smtp();
$this->middleware('guest', ['except' => 'getLogout']);
}
@@ -186,6 +185,7 @@ class AuthController extends Controller
*/
public function postLogin(LoginRequest $request)
{
\Event::fire('auth.login.event', []); //added 5/5/2016
// Set login attempts and login time
$value = $_SERVER['REMOTE_ADDR'];
$usernameinput = $request->input('email');
@@ -227,10 +227,10 @@ class AuthController extends Controller
$password = $request->input('password');
$field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
// If attempts > 3 and time < 10 minutes
// if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60))) {
if ($loginAttempts > $security->backlist_threshold && (time() - $loginAttemptTime <= ($security->lockout_period * 60))) {
//
// return redirect()->back()->withErrors('email', 'incorrect email')->with('error', $security->lockout_message);
// }
return redirect()->back()->withErrors('email', 'incorrect email')->with('error', $security->lockout_message);
}
// If time > 10 minutes, reset attempts counter and time in session
if (time() - $loginAttemptTime > ($security->lockout_period * 60)) {
\Session::put('loginAttempts', 1);
@@ -243,7 +243,7 @@ class AuthController extends Controller
}
// If auth ok, redirect to restricted area
\Session::put('loginAttempts', $loginAttempts + 1);
\Event::fire('auth.login.event', []); //added 5/5/2016
if (Auth::Attempt([$field => $usernameinput, 'password' => $password], $request->has('remember'))) {
if (Auth::user()->role == 'user') {
return \Redirect::route('/');
@@ -277,13 +277,15 @@ class AuthController extends Controller
if ($data) {
$attempts = $data->Attempts + 1;
if ($attempts == $apt) {
$result = DB::select('UPDATE login_attempts SET Attempts='.$attempts.", LastLogin=NOW() WHERE IP = '$value' OR User = '$field'");
// $result = DB::select('UPDATE login_attempts SET Attempts='.$attempts.", LastLogin=NOW() WHERE IP = '$value' OR User = '$field'");
$result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts, 'LastLogin' => Date('Y-m-d H:i:s')]);
} else {
$result = DB::table('login_attempts')->where('IP', '=', $value)->orWhere('User', '=', $field)->update(['Attempts' => $attempts]);
// $result = DB::select("UPDATE login_attempts SET Attempts=".$attempts." WHERE IP = '$value' OR User = '$field'");
}
} else {
$result = DB::select("INSERT INTO login_attempts (Attempts,User,IP,LastLogin) values (1,'$field','$value', NOW())");
// $result = DB::select("INSERT INTO login_attempts (Attempts,User,IP,LastLogin) values (1,'$field','$value', NOW())");
$result = DB::table('login_attempts')->update(['Attempts' => 1, 'User' => $field, 'IP' => $value, 'LastLogin' => Date('Y-m-d H:i:s')]);
}
}
@@ -326,7 +328,6 @@ class AuthController extends Controller
return 1;
} else {
$this->clearLoginAttempts($value, $field);
return 0;
}
}

View File

@@ -32,7 +32,6 @@ class PasswordController extends Controller
{
$this->PhpMailController = $PhpMailController;
$this->middleware('guest');
SettingsController::smtp();
}
/**
@@ -54,6 +53,7 @@ class PasswordController extends Controller
{
$date = date('Y-m-d H:i:s');
$this->validate($request, ['email' => 'required|email']);
\Event::fire('reset.password',array());
$user = User::where('email', '=', $request->only('email'))->first();
if (isset($user)) {
$user1 = $user->email;
@@ -71,7 +71,7 @@ class PasswordController extends Controller
return redirect()->back()->with('status', Lang::get('lang.we_have_e-mailed_your_password_reset_link'));
} else {
return redirect()->back()->with('errors', Lang::get("lang.we_can't_find_a_user_with_that_e-mail_address"));
return redirect()->back()->with('fails', Lang::get("lang.we_can't_find_a_user_with_that_e-mail_address"));
}
}
}

View File

@@ -327,18 +327,18 @@ class UserController extends Controller
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
$destinationPath = 'lb-faveo/profilepic';
$destinationPath = 'uploads/profilepic';
$user->profile_pic = $name;
} elseif ($request->input('gender') == 0) {
$name = 'avatar2.png';
$destinationPath = 'lb-faveo/profilepic';
$destinationPath = 'uploads/profilepic';
$user->profile_pic = $name;
}
}
if (Input::file('profile_pic')) {
//$extension = Input::file('profile_pic')->getClientOriginalExtension();
$name = Input::file('profile_pic')->getClientOriginalName();
$destinationPath = 'lb-faveo/profilepic';
$destinationPath = 'uploads/profilepic';
$fileName = rand(0000, 9999).'.'.$name;
//echo $fileName;
Input::file('profile_pic')->move($destinationPath, $fileName);

View File

@@ -33,16 +33,15 @@ use Redirect;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class FormController extends Controller
{
class FormController extends Controller {
/**
* Create a new controller instance.
* Constructor to check.
*
* @return void
*/
public function __construct(TicketWorkflowController $TicketWorkflowController)
{
public function __construct(TicketWorkflowController $TicketWorkflowController) {
$this->middleware('board');
// creating a TicketController instance
$this->TicketWorkflowController = $TicketWorkflowController;
@@ -55,18 +54,21 @@ class FormController extends Controller
*
* @return type
*/
public function getForm(Help_topic $topic, CountryCode $code)
{
public function getForm(Help_topic $topic, CountryCode $code) {
if (\Config::get('database.install') == '%0%') {
return \Redirect::route('license');
return \Redirect::route('licence');
}
$location = GeoIP::getLocation('');
$phonecode = $code->where('iso', '=', $location['isoCode'])->first();
if (System::first()->status == 1) {
$topics = $topic->get();
$codes = $code->get();
return view('themes.default1.client.helpdesk.form', compact('topics', 'codes'))->with('phonecode', $phonecode->phonecode);
if ($phonecode->phonecode) {
$phonecode = $phonecode->phonecode;
} else {
$phonecode = "";
}
return view('themes.default1.client.helpdesk.form', compact('topics', 'codes'))->with('phonecode', $phonecode);
} else {
return \Redirect::route('home');
}
@@ -80,46 +82,46 @@ class FormController extends Controller
*
* @return type string
*/
public function postForm($id, Help_topic $topic)
{
public function postForm($id, Help_topic $topic) {
if ($id != 0) {
$helptopic = $topic->where('id', '=', $id)->first();
$custom_form = $helptopic->custom_form;
$values = Fields::where('forms_id', '=', $custom_form)->get();
if (!$values) {
}
if ($values) {
foreach ($values as $value) {
if ($value->type == 'select') {
$data = $value->value;
$value = explode(',', $data);
echo '<select class="form-control">';
foreach ($value as $option) {
echo '<option>'.$option.'</option>';
foreach ($values as $form_data) {
if ($form_data->type == "select") {
$form_fields = explode(',', $form_data->value);
$var = "";
foreach ($form_fields as $form_field) {
$var .= '<option value="' . $form_field . '">' . $form_field . '</option>';
}
echo '</select></br>';
} elseif ($value->type == 'radio') {
$type2 = $value->value;
$val = explode(',', $type2);
echo '<label class="radio-inline">'.$value->label.'</label>&nbsp&nbsp&nbsp<input type="'.$value->type.'" name="'.$value->name.'">&nbsp;&nbsp;'.$val[0].'
&nbsp&nbsp&nbsp<input type="'.$value->type.'" name="'.$value->name.'">&nbsp;&nbsp;'.$val[1].'</br>';
} elseif ($value->type == 'textarea') {
$type3 = $value->value;
$v = explode(',', $type3);
//dd($v);
if (array_key_exists(1, $v)) {
echo '<label>'.$value->label.'</label></br><textarea class=form-control rows="'.$v[0].'" cols="'.$v[1].'"></textarea></br>';
} else {
echo '<label>'.$value->label.'</label></br><textarea class=form-control rows="10" cols="60"></textarea></br>';
echo '<br/><label>' . ucfirst($form_data->label) . '</label><select class="form-control" name="' . $form_data->name . '">' . $var . '</select>';
} elseif ($form_data->type == "radio") {
$type2 = $form_data->value;
$vals = explode(',', $type2);
echo '<br/><label>' . ucfirst($form_data->label) . '</label><br/>';
foreach ($vals as $val) {
echo '<input type="' . $form_data->type . '" name="' . $form_data->name . '"> ' . $val . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
}
echo "<br/>";
} elseif ($form_data->type == "textarea") {
$type3 = $form_data->value;
echo '<br/><label>' . $form_data->label . '</label></br><textarea id="unique-textarea" name="' . $form_data->name . '" class="form-control" style="height:15%;"></textarea>';
} elseif ($form_data->type == "checkbox") {
$type4 = $form_data->value;
$checks = explode(',', $type4);
echo '<br/><label>' . ucfirst($form_data->label) . '</label><br/>';
foreach ($checks as $check) {
echo '<input type="' . $form_data->type . '" name="' . $form_data->name . '">&nbsp&nbsp' . $check;
}
} elseif ($value->type == 'checkbox') {
$type4 = $value->value;
$check = explode(',', $type4);
echo '<label class="radio-inline">'.$value->label.'&nbsp&nbsp&nbsp<input type="'.$value->type.'" name="'.$value->name.'">&nbsp&nbsp'.$check[0].'</label><label class="radio-inline"><input type="'.$value->type.'" name="'.$value->name.'">&nbsp&nbsp'.$check[1].'</label></br>';
} else {
echo '<label>'.$value->label.'</label><input type="'.$value->type.'" class="form-control" name="'.$value->name.'" /></br>';
echo '<br/><label>' . ucfirst($form_data->label) . '</label><input type="' . $form_data->type . '" class="form-control" name="' . $form_data->name . '" />';
}
}
echo '<br/><br/>';
}
} else {
return;
@@ -132,8 +134,7 @@ class FormController extends Controller
* @param type Request $request
* @param type User $user
*/
public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code)
{
public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code) {
$form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token');
$name = $request->input('Name');
@@ -142,12 +143,16 @@ class FormController extends Controller
$subject = $request->input('Subject');
$details = $request->input('Details');
$phonecode = $request->input('Code');
$System = System::where('id', '=', 1)->first();
$departments = Department::where('id', '=', $System->department)->first();
$department = $departments->id;
$mobile_number = $request->input('Mobile');
$status = $ticket_settings->first()->status;
$helptopic = $ticket_settings->first()->help_topic;
$helptopic = $request->input('helptopic');
$helpTopicObj = Help_topic::where('id','=', $helptopic);
if($helpTopicObj->exists() && ($helpTopicObj->value('status')==1)){
$department = $helpTopicObj->value('department');
}else{
$defaultHelpTopicID = Ticket::where('id', '=', '1')->first()->help_topic;
$department = Help_topic::where('id','=', $defaultHelpTopicID)->value('department');
}
$sla = $ticket_settings->first()->sla;
$priority = $ticket_settings->first()->priority;
$source = $ticket_source->where('name', '=', 'web')->first()->id;
@@ -161,8 +166,8 @@ class FormController extends Controller
$geoipcode = $code->where('iso', '=', $location['isoCode'])->first();
if ($phonecode == null) {
$data = [
'fails' => Lang::get('lang.country-code-required-error'),
'phonecode' => $geoipcode->phonecode,
'fails' => Lang::get('lang.country-code-required-error'),
'phonecode' => $geoipcode->phonecode,
'country_code_error' => 1,
];
@@ -171,8 +176,8 @@ class FormController extends Controller
$code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get();
if (!count($code)) {
$data = [
'fails' => Lang::get('lang.incorrect-country-code-error'),
'phonecode' => $geoipcode->phonecode,
'fails' => Lang::get('lang.incorrect-country-code-error'),
'phonecode' => $geoipcode->phonecode,
'country_code_error' => 1,
];
@@ -197,9 +202,10 @@ class FormController extends Controller
}
}
}
return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is').' '.$result[0].'. '.Lang::get('lang.Please-save-this-for-future-reference'));
// dd($result);
return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is') . ' ' . $result[0] . '. ' . Lang::get('lang.Please-save-this-for-future-reference'));
}
// dd($result);
}
/**
@@ -209,14 +215,13 @@ class FormController extends Controller
*
* @return type view
*/
public function post_ticket_reply($id, Request $request)
{
public function post_ticket_reply($id, Request $request) {
try {
if ($comment != null) {
$tickets = Tickets::where('id', '=', $id)->first();
$thread = Ticket_Thread::where('ticket_id', '=', $tickets->id)->first();
$subject = $thread->title.'[#'.$tickets->ticket_number.']';
$subject = $thread->title . '[#' . $tickets->ticket_number . ']';
$body = $request->input('comment');
$user_cred = User::where('id', '=', $tickets->user_id)->first();
@@ -248,29 +253,24 @@ class FormController extends Controller
} catch (Exception $e) {
return \Redirect::back()->with('fails1', $e->getMessage());
}
//
// $comment = $request->input('comment');
// if ($comment != null) {
// $tickets = Tickets::where('id', '=', $id)->first();
// $threads = new Ticket_Thread();
// $tickets->closed_at = null;
// $tickets->closed = 0;
// $tickets->reopened_at = date('Y-m-d H:i:s');
// $tickets->reopened = 1;
// $threads->user_id = $tickets->user_id;
// $threads->ticket_id = $tickets->id;
// $threads->poster = 'client';
// $threads->body = $comment;
// try {
// $threads->save();
// $tickets->save();
//
// return \Redirect::back()->with('success1', Lang::get('lang.successfully_replied'));
// } catch (Exception $e) {
// return \Redirect::back()->with('fails1', $e->getMessage());
// }
// } else {
// return \Redirect::back()->with('fails1', Lang::get('lang.please_fill_some_data'));
// }
}
}
public function getCustomForm(Request $request) {
$html = "";
$helptopic_id = $request->input('helptopic');
$helptopics = new Help_topic();
$helptopic = $helptopics->find($helptopic_id);
if (!$helptopic) {
throw new Exception("We can not find your request");
}
$custom_form = $helptopic->custom_form;
if ($custom_form) {
$fields = new Fields();
$forms = new \App\Model\helpdesk\Form\Forms();
$form_controller = new \App\Http\Controllers\Admin\helpdesk\FormController($fields, $forms);
$html = $form_controller->renderForm($custom_form);
}
return $html;
}
}

View File

@@ -16,6 +16,7 @@ use App\Model\helpdesk\Settings\System;
use App\Model\helpdesk\Ticket\Ticket_Thread;
use App\Model\helpdesk\Ticket\Tickets;
use App\Model\helpdesk\Utility\CountryCode;
use App\Model\helpdesk\Settings\CommonSettings;
use App\User;
use Auth;
// classes
@@ -76,18 +77,18 @@ class GuestController extends Controller
if ($user->profile_pic == 'avatar5.png' || $user->profile_pic == 'avatar2.png') {
if ($request->input('gender') == 1) {
$name = 'avatar5.png';
$destinationPath = 'lb-faveo/media/profilepic';
$destinationPath = 'uploads/profilepic';
$user->profile_pic = $name;
} elseif ($request->input('gender') == 0) {
$name = 'avatar2.png';
$destinationPath = 'lb-faveo/media/profilepic';
$destinationPath = 'uploads/profilepic';
$user->profile_pic = $name;
}
}
if (Input::file('profile_pic')) {
//$extension = Input::file('profile_pic')->getClientOriginalExtension();
$name = Input::file('profile_pic')->getClientOriginalName();
$destinationPath = 'lb-faveo/media/profilepic';
$destinationPath = 'uploads/profilepic';
$fileName = rand(0000, 9999).'.'.$name;
//echo $fileName;
Input::file('profile_pic')->move($destinationPath, $fileName);
@@ -138,7 +139,7 @@ class GuestController extends Controller
public function getForm(Help_topic $topic)
{
if (\Config::get('database.install') == '%0%') {
return \Redirect::route('license');
return \Redirect::route('licence');
}
if (System::first()->status == 1) {
$topics = $topic->get();
@@ -316,11 +317,13 @@ class GuestController extends Controller
*
* @return type
*/
public function get_ticket_email($id)
public function get_ticket_email($id, CommonSettings $common_settings)
{
$id1 = \Crypt::decrypt($id);
return view('themes.default1.client.helpdesk.ckeckticket', compact('id'));
$common_setting = $common_settings->select('status')
->where('option_name', '=', 'user_set_ticket_status')
->first();
return view('themes.default1.client.helpdesk.ckeckticket', compact('id', 'common_setting'));
}
/**

View File

@@ -279,7 +279,7 @@ class UnAuthController extends Controller
return Lang::get('lang.your_ticket_has_been').' '.$ticket_status->state;
}
//Auto-close tickets
//Auto-close tickets
public function autoCloseTickets()
{
$workflow = \App\Model\helpdesk\Workflow\WorkflowClose::whereId(1)->first();

View File

@@ -19,7 +19,7 @@ class WelcomepageController extends Controller
{
public function __construct()
{
// $this->middleware('board');
// $this->middleware('board');
}
/**

View File

@@ -24,18 +24,10 @@ use Lang;
use Mail;
use Redirect;
class UserController extends Controller
{
public function __construct()
{
class UserController extends Controller {
public function __construct() {
$this->middleware('board');
//$this->middleware('auth');
//SettingsController::language();
// $this->port();
// $this->host();
// $this->password();
// $this->encryption();
// $this->email();
}
/**
@@ -43,23 +35,16 @@ class UserController extends Controller
*
* @return response
*/
public function getArticle(Article $article, Category $category, Settings $settings)
{
$settings = $settings->first();
$pagination = $settings->pagination;
if (Auth::check()) {
if (\Auth::user()->role == 'user') {
$article = $article->where('status', '1');
}
} else {
public function getArticle(Article $article, Category $category, Settings $settings) {
$setting = $settings->first();
$pagination = $setting->pagination;
if (\Auth::user()->role == 'user' || !Auth::check()) {
$article = $article->where('status', '1');
}
$article = $article->where('type', '1');
$article = $article->paginate($pagination);
// dd($article);
$article->setPath('article-list');
$categorys = $category->get();
// $time = $this->timezone($utc);
return view('themes.default1.client.kb.article-list.articles', compact('time', 'categorys', 'article'));
}
@@ -72,8 +57,7 @@ class UserController extends Controller
*
* @return string excerpt
*/
public static function getExcerpt($str, $startPos = 0, $maxLength = 50)
{
public static function getExcerpt($str, $startPos = 0, $maxLength = 50) {
if (strlen($str) > $maxLength) {
$excerpt = substr($str, $startPos, $maxLength - 3);
$lastSpace = strrpos($excerpt, ' ');
@@ -96,14 +80,13 @@ class UserController extends Controller
*
* @return type view
*/
public function search(SearchRequest $request, Category $category, Article $article, Settings $settings)
{
public function search(SearchRequest $request, Category $category, Article $article, Settings $settings) {
$settings = $settings->first();
$pagination = $settings->pagination;
$search = $request->input('s');
$result = $article->where('name', 'LIKE', '%'.$search.'%')
->orWhere('slug', 'LIKE', '%'.$search.'%')
->orWhere('description', 'LIKE', '%'.$search.'%')
$result = $article->where('name', 'LIKE', '%' . $search . '%')
->orWhere('slug', 'LIKE', '%' . $search . '%')
->orWhere('description', 'LIKE', '%' . $search . '%')
->paginate($pagination);
$result->setPath('search');
$categorys = $category->get();
@@ -116,34 +99,31 @@ class UserController extends Controller
*
* @return response
*/
public function show($slug, Article $article, Category $category)
{
public function show($slug, Article $article, Category $category) {
//ArticleController::timezone();
$tz = \App\Model\helpdesk\Settings\System::where('id', '1')->first()->time_zone;
$tz = \App\Model\helpdesk\Utility\Timezones::where('id', $tz)->first()->name;
date_default_timezone_set($tz);
$date = \Carbon\Carbon::now()->toDateTimeString();
$arti = $article->where('slug', $slug);
if (Auth::check()) {
if (\Auth::user()->role == 'user') {
$arti = $arti->where('status', '1');
}
} else {
if (!Auth::check()|| \Auth::user()->role == 'user') {
$arti = $arti->where('status', '1');
$arti = $arti->where('publish_time', '<', $date);
}
$arti = $arti->where('type', '1');
$arti = $arti->where('publish_time', '<', $date);
$arti = $arti->first();
if ($arti) {
return view('themes.default1.client.kb.article-list.show', compact('arti'));
} else {
return redirect()->back()->with('fails', Lang::get('lang.no_records_on_publish_time'));
return redirect('404');
}
}
public function getCategory($slug, Article $article, Category $category, Relationship $relation)
{
public function getCategory($slug, Article $article, Category $category, Relationship $relation) {
/* get the article_id where category_id == current category */
$catid = $category->where('slug', $slug)->first();
if (!$catid) {
@@ -159,8 +139,7 @@ class UserController extends Controller
return view('themes.default1.client.kb.article-list.category', compact('all', 'id', 'categorys', 'article_id'));
}
public function home(Article $article, Category $category, Relationship $relation)
{
public function home(Article $article, Category $category, Relationship $relation) {
if (Config::get('database.install') == '%0%') {
return redirect('step1');
} else {
@@ -172,8 +151,7 @@ class UserController extends Controller
}
}
public function Faq(Faq $faq, Category $category)
{
public function Faq(Faq $faq, Category $category) {
$faq = $faq->where('id', '1')->first();
$categorys = $category->get();
@@ -185,8 +163,7 @@ class UserController extends Controller
*
* @return response
*/
public function contact(Category $category, Settings $settings)
{
public function contact(Category $category, Settings $settings) {
$settings = $settings->whereId('1')->first();
$categorys = $category->get();
@@ -198,8 +175,7 @@ class UserController extends Controller
*
* @return response
*/
public function postContact(ContactRequest $request, Contact $contact)
{
public function postContact(ContactRequest $request, Contact $contact) {
$this->port();
$this->host();
$this->encryption();
@@ -217,8 +193,8 @@ class UserController extends Controller
//echo $message;
//echo $contact->email;
$mail = Mail::send('themes.default1.client.kb.article-list.contact-details', ['name' => $name, 'email' => $email, 'subject' => $subject, 'details' => $details], function ($message) use ($contact) {
$message->to($contact->email, $contact->name)->subject('Contact');
});
$message->to($contact->email, $contact->name)->subject('Contact');
});
if ($mail) {
return redirect('contact')->with('success', Lang::get('lang.your_details_send_to_system'));
} else {
@@ -226,8 +202,7 @@ class UserController extends Controller
}
}
public function contactDetails()
{
public function contactDetails() {
return view('themes.default1.client.kb.article-list.contact-details');
}
@@ -241,9 +216,11 @@ class UserController extends Controller
*
* @return type response
*/
public function postComment($slug, Article $article, CommentRequest $request, Comment $comment)
{
public function postComment($slug, Article $article, CommentRequest $request, Comment $comment) {
$article = $article->where('slug', $slug)->first();
if(!$article){
return Redirect::back()->with('fails', Lang::get('lang.sorry_not_processed'));
}
$id = $article->id;
$comment->article_id = $id;
if ($comment->fill($request->input())->save()) {
@@ -253,46 +230,42 @@ class UserController extends Controller
}
}
public function getPage($name, Page $page)
{
public function getPage($name, Page $page) {
$page = $page->where('slug', $name)->first();
//$this->timezone($page->created_at);
return view('themes.default1.client.kb.article-list.pages', compact('page'));
if($page){
return view('themes.default1.client.kb.article-list.pages', compact('page'));
}else{
return Redirect::back()->with('fails', Lang::get('lang.sorry_not_processed'));
}
}
public static function port()
{
public static function port() {
$setting = Settings::whereId('1')->first();
Config::set('mail.port', $setting->port);
}
public static function host()
{
public static function host() {
$setting = Settings::whereId('1')->first();
Config::set('mail.host', $setting->host);
}
public static function encryption()
{
public static function encryption() {
$setting = Settings::whereId('1')->first();
Config::set(['mail.encryption' => $setting->encryption, 'mail.username' => $setting->email]);
}
public static function email()
{
public static function email() {
$setting = Settings::whereId('1')->first();
Config::set(['mail.from' => ['address' => $setting->email, 'name' => 'asd']]);
//dd(Config::get('mail'));
}
public static function password()
{
public static function password() {
$setting = Settings::whereId('1')->first();
Config::set(['mail.password' => $setting->password, 'mail.sendmail' => $setting->email]);
}
public function getCategoryList(Article $article, Category $category, Relationship $relation)
{
public function getCategoryList(Article $article, Category $category, Relationship $relation) {
//$categorys = $category->get();
$categorys = $category->get();
// $categorys->setPath('home');
@@ -314,15 +287,13 @@ class UserController extends Controller
// //return substr($date, 0, -6);
// }
public function clientProfile()
{
public function clientProfile() {
$user = Auth::user();
return view('themes.default1.client.kb.article-list.profile', compact('user'));
}
public function postClientProfile($id, ProfileRequest $request)
{
public function postClientProfile($id, ProfileRequest $request) {
$user = Auth::user();
$user->gender = $request->input('gender');
$user->save();
@@ -341,7 +312,7 @@ class UserController extends Controller
//$extension = Input::file('profile_pic')->getClientOriginalExtension();
$name = Input::file('profile_pic')->getClientOriginalName();
$destinationPath = 'lb-faveo/dist/img';
$fileName = rand(0000, 9999).'.'.$name;
$fileName = rand(0000, 9999) . '.' . $name;
//echo $fileName;
Input::file('profile_pic')->move($destinationPath, $fileName);
$user->profile_pic = $fileName;
@@ -355,8 +326,7 @@ class UserController extends Controller
}
}
public function postClientProfilePassword($id, ProfilePassword $request)
{
public function postClientProfilePassword($id, ProfilePassword $request) {
$user = Auth::user();
//echo $user->password;
if (Hash::check($request->input('old_password'), $user->getAuthPassword())) {
@@ -368,4 +338,5 @@ class UserController extends Controller
return redirect()->back()->with('fails', Lang::get('lang.password_was_not_updated'));
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Http\Controllers\Common;
use App\Http\Controllers\Controller;
class FileuploadController extends Controller {
public function __construct() {
// checking authentication
$this->middleware('auth');
// checking if role is agent
$this->middleware('role.agent');
}
// Returns a file size limit in bytes based on the PHP upload_max_filesize
// and post_max_size
function file_upload_max_size() {
static $max_size = -1;
if ($max_size < 0) {
// Start with post_max_size.
$max_size_in_bytes = $this->parse_size(ini_get('post_max_size'));
$max_size_in_actual = ini_get('post_max_size');
// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = $this->parse_size(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size_in_bytes = $upload_max;
$max_size_in_actual = ini_get('upload_max_filesize');
}
}
return ['0' => $max_size_in_bytes, '1' => $max_size_in_actual];
// return $max_size_in_bytes;
}
function parse_size($size) {
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
} else {
return round($size);
}
}
}

View File

@@ -5,84 +5,110 @@ namespace App\Http\Controllers\Common;
use App\Http\Controllers\Controller;
use App\Model\helpdesk\Notification\Notification;
use App\Model\helpdesk\Notification\UserNotification;
use App\Model\helpdesk\Ticket\Tickets;
use App\User;
use App\Http\Controllers\Api\v1\PushNotificationController;
use App\Model\helpdesk\Notification\NotificationType;
class NotificationController extends Controller
{
class NotificationController extends Controller {
/**
*********************************************
* Class Notification Controller
*********************************************
* This controller is used to generate in app notification
* under the folling occurrence
* 1. Ticket Creation
* 2. Ticket Reply
* 3. User Creation
*
* @author Ladybird <info@ladybirdweb.com>
*/
public $user;
public function __construct()
{
/**
* Constructor
*/
public function __construct(PushNotificationController $PushNotificationController) {
$this->PushNotificationController = $PushNotificationController;
$user = new User();
$this->user = $user;
// checking authentication
$this->middleware('auth');
// checking if role is agent
$this->middleware('role.agent');
}
/**
* get the page to list the notifications.
*
* @return response
* This function is used to create in app notifications.
* @param type $model_id
* @param type $userid_created
* @param type $type_id
* @param type $forwhome
*/
public static function getNotifications()
{
$notifications = UserNotification::join('notifications', 'user_notification.notification_id', '=', 'notifications.id')
->join('notification_types', 'notifications.type_id', '=', 'notification_types.id')
->where('user_notification.user_id', '=', \Auth::user()->id)
->paginate(10);
return $notifications;
}
public function create($model_id, $userid_created, $type_id, $forwhome = [])
{
public function create($model_id, $userid_created, $type_id, $forwhome = []) {
try {
if (empty($forwhome)) {
$forwhome = $this->user->where('role', '!=', 'user')->get()->toArray();
$ticket = Tickets::where('id', '=', $model_id)->first();
$forwhome = $this->user->where('role', '=', 'agent')->where('primary_dpt', '=', $ticket->dept_id)->get();
$forwhome2 = $this->user->where('role', '=', 'admin')->get();
$forwhome = $forwhome->merge($forwhome2);
}
//dd($forwhome);
//system notification
$notification = new Notification();
$UN = new UserNotification();
$notify = $notification->create(['model_id' => $model_id, 'userid_created' => $userid_created, 'type_id' => $type_id]);
// system notification
$notify = Notification::create(['model_id' => $model_id, 'userid_created' => $userid_created, 'type_id' => $type_id]);
foreach ($forwhome as $agent) {
$user_notify = $UN->create(['notification_id' => $notify->id, 'user_id' => $agent['id'], 'is_read' => 0]);
$type_message = NotificationType::where('id', '=', $type_id)->first();
UserNotification::create(['notification_id' => $notify->id, 'user_id' => $agent['id'], 'is_read' => 0]);
// $this->PushNotificationController->response($agent->fcm_token, $type_message->message . $model_id, $model_id);
}
} catch (\Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
}
public function markAllRead($id)
{
/**
* This function is to mark all ticket to read status
* @param type $id
* @return int
*/
public function markAllRead($id) {
$markasread = UserNotification::where('user_id', '=', \Auth::user()->id)->where('is_read', '=', '0')->get();
foreach ($markasread as $mark) {
$mark->is_read = '1';
$mark->save();
}
return 1;
}
public function markRead($id)
{
/**
* This function to mark read
* @param type $id
* @return int
*/
public function markRead($id) {
$markasread = UserNotification::where('notification_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->where('is_read', '=', '0')->get();
foreach ($markasread as $mark) {
$mark->is_read = '1';
$mark->save();
}
return 1;
}
public function show()
{
/**
* function to show all the notifications
* @return type
*/
public function show() {
$notifications = $this->getNotifications();
return view('notifications-all', compact('notifications'));
}
public function delete($id)
{
/**
* function to delete notifications
* @param type $id
* @return int
*/
public function delete($id) {
$markasread = UserNotification::where('notification_id', '=', $id)->where('user_id', '=', \Auth::user()->id)->get();
foreach ($markasread as $mark) {
$mark->delete();
@@ -90,4 +116,17 @@ class NotificationController extends Controller
return 1;
}
/**
* get the page to list the notifications.
* @return response
*/
public static function getNotifications() {
$notifications = UserNotification::join('notifications', 'user_notification.notification_id', '=', 'notifications.id')
->join('notification_types', 'notifications.type_id', '=', 'notification_types.id')
->where('user_notification.user_id', '=', \Auth::user()->id)
->paginate(10);
return $notifications;
}
}

View File

@@ -8,15 +8,14 @@ use App\Model\helpdesk\Agent\Department;
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Settings\Company;
use App\Model\helpdesk\Settings\Email;
use App\Model\helpdesk\Settings\CommonSettings;
use App\User;
use Auth;
class PhpMailController extends Controller
{
public function fetch_smtp_details($id)
{
$emails = Emails::where('id', '=', $id)->first();
class PhpMailController extends Controller {
public function fetch_smtp_details($id) {
$emails = Emails::where('id', '=', $id)->first();
return $emails;
}
@@ -25,269 +24,266 @@ class PhpMailController extends Controller
*
* @return Mail
*/
public function sendmail($from, $to, $message, $template_variables)
{
// dd($from);
$from_address = $this->fetch_smtp_details($from);
if ($from_address == null) {
return $from_address;
} else {
// dd($from_address);
$username = $from_address->email_address;
$fromname = $from_address->email_name;
$password = \Crypt::decrypt($from_address->password);
$smtpsecure = $from_address->sending_encryption;
$host = $from_address->sending_host;
$port = $from_address->sending_port;
$protocol = $from_address->sending_protocol;
public function sendmail($from, $to, $message, $template_variables) {
// try {
// dd($from);
$from_address = $this->fetch_smtp_details($from);
if ($from_address == null) {
return $from_address;
} else {
// dd($from_address);
$username = $from_address->email_address;
$fromname = $from_address->email_name;
$password = \Crypt::decrypt($from_address->password);
$smtpsecure = $from_address->sending_encryption;
$host = $from_address->sending_host;
$port = $from_address->sending_port;
$protocol = $from_address->sending_protocol;
if (isset($to['email'])) {
$recipants = $to['email'];
} else {
$recipants = null;
}
if (isset($to['name'])) {
$recipantname = $to['name'];
} else {
$recipantname = null;
}
if (isset($to['cc'])) {
$cc = $to['cc'];
} else {
$cc = null;
}
if (isset($to['bc'])) {
$bc = $to['bc'];
} else {
$bc = null;
}
// if (isset($message['subject'])) {
// $subject = $message['subject'];
// } else {
// $subject = null;
// }
if (isset($message['body'])) {
$content = $message['body'];
} else {
$content = null;
}
if (isset($message['scenario'])) {
$template = $message['scenario'];
} else {
$template = null;
}
if (isset($message['attachments'])) {
$attachment = $message['attachments'];
} else {
$attachment = null;
}
if (isset($to['email'])) {
$recipants = $to['email'];
} else {
$recipants = null;
}
if (isset($to['name'])) {
$recipantname = $to['name'];
} else {
$recipantname = null;
}
if (isset($to['cc'])) {
$cc = $to['cc'];
} else {
$cc = null;
}
if (isset($to['bc'])) {
$bc = $to['bc'];
} else {
$bc = null;
}
// if (isset($message['subject'])) {
// $subject = $message['subject'];
// } else {
// $subject = null;
// }
if (isset($message['body'])) {
$content = $message['body'];
} else {
$content = null;
}
if (isset($message['scenario'])) {
$template = $message['scenario'];
} else {
$template = null;
}
if (isset($message['attachments'])) {
$attachment = $message['attachments'];
} else {
$attachment = null;
}
// template variables
if (Auth::user()) {
$agent = Auth::user()->user_name;
} else {
$agent = null;
}
if (isset($template_variables['ticket_agent_name'])) {
$ticket_agent_name = $template_variables['ticket_agent_name'];
} else {
$ticket_agent_name = null;
}
if (isset($template_variables['ticket_number'])) {
$ticket_number = $template_variables['ticket_number'];
} else {
$ticket_number = null;
}
if (isset($template_variables['ticket_client_name'])) {
$ticket_client_name = $template_variables['ticket_client_name'];
} else {
$ticket_client_name = null;
}
if (isset($template_variables['ticket_client_email'])) {
$ticket_client_email = $template_variables['ticket_client_email'];
} else {
$ticket_client_email = null;
}
if (isset($template_variables['ticket_body'])) {
$ticket_body = $template_variables['ticket_body'];
} else {
$ticket_body = null;
}
if (isset($template_variables['ticket_assigner'])) {
$ticket_assigner = $template_variables['ticket_assigner'];
} else {
$ticket_assigner = null;
}
if (isset($template_variables['ticket_link_with_number'])) {
$ticket_link_with_number = $template_variables['ticket_link_with_number'];
} else {
$ticket_link_with_number = null;
}
// if (isset($template_variables['system_from'])) {
// $system_from = $template_variables['system_from'];
// } else {
// $system_from = null;
// }
if (isset($template_variables['system_link'])) {
$system_link = $template_variables['system_link'];
} else {
$system_link = null;
}
if (isset($template_variables['system_error'])) {
$system_error = $template_variables['system_error'];
} else {
$system_error = null;
}
if (isset($template_variables['agent_sign'])) {
$agent_sign = $template_variables['agent_sign'];
} else {
$agent_sign = null;
}
if (isset($template_variables['department_sign'])) {
$department_sign = $template_variables['department_sign'];
} else {
$department_sign = null;
}
if (isset($template_variables['password_reset_link'])) {
$password_reset_link = $template_variables['password_reset_link'];
} else {
$password_reset_link = null;
}
if (isset($template_variables['user_password'])) {
$user_password = $template_variables['user_password'];
} else {
$user_password = null;
}
if (isset($template_variables['email_address'])) {
$email_address = $template_variables['email_address'];
} else {
$email_address = null;
}
if (isset($template_variables['user'])) {
$user = $template_variables['user'];
} else {
$user = null;
}
// template variables
if (Auth::user()) {
$agent = Auth::user()->user_name;
} else {
$agent = null;
}
if (isset($template_variables['ticket_agent_name'])) {
$ticket_agent_name = $template_variables['ticket_agent_name'];
} else {
$ticket_agent_name = null;
}
if (isset($template_variables['ticket_number'])) {
$ticket_number = $template_variables['ticket_number'];
} else {
$ticket_number = null;
}
if (isset($template_variables['ticket_client_name'])) {
$ticket_client_name = $template_variables['ticket_client_name'];
} else {
$ticket_client_name = null;
}
if (isset($template_variables['ticket_client_email'])) {
$ticket_client_email = $template_variables['ticket_client_email'];
} else {
$ticket_client_email = null;
}
if (isset($template_variables['ticket_body'])) {
$ticket_body = $template_variables['ticket_body'];
} else {
$ticket_body = null;
}
if (isset($template_variables['ticket_assigner'])) {
$ticket_assigner = $template_variables['ticket_assigner'];
} else {
$ticket_assigner = null;
}
if (isset($template_variables['ticket_link_with_number'])) {
$ticket_link_with_number = $template_variables['ticket_link_with_number'];
} else {
$ticket_link_with_number = null;
}
if (isset($template_variables['system_from'])) {
$system_from = $template_variables['system_from'];
} else {
$system_from = $this->company();
}
if (isset($template_variables['system_link'])) {
$system_link = $template_variables['system_link'];
} else {
$system_link = url('/');
}
if (isset($template_variables['system_error'])) {
$system_error = $template_variables['system_error'];
} else {
$system_error = null;
}
if (isset($template_variables['agent_sign'])) {
$agent_sign = $template_variables['agent_sign'];
} else {
$agent_sign = null;
}
if (isset($template_variables['department_sign'])) {
$department_sign = $template_variables['department_sign'];
} else {
$department_sign = null;
}
if (isset($template_variables['password_reset_link'])) {
$password_reset_link = $template_variables['password_reset_link'];
} else {
$password_reset_link = null;
}
if (isset($template_variables['user_password'])) {
$user_password = $template_variables['user_password'];
} else {
$user_password = null;
}
if (isset($template_variables['email_address'])) {
$email_address = $template_variables['email_address'];
} else {
$email_address = null;
}
if (isset($template_variables['user'])) {
$user = $template_variables['user'];
} else {
$user = null;
}
$system_link = url('/');
// $system_link = url('/');
$system_from = $this->company();
// $system_from = $this->company();
$mail = new \PHPMailer();
$mail = new \PHPMailer();
$status = \DB::table('settings_email')->first();
$status = \DB::table('settings_email')->first();
$path2 = \Config::get('view.paths');
$path2 = \Config::get('view.paths');
// $directory = $path2[0].DIRECTORY_SEPARATOR.'emails'.DIRECTORY_SEPARATOR.$status->template.DIRECTORY_SEPARATOR;
//
// $handle = fopen($directory.$template.'.blade.php', 'r');
// $contents = fread($handle, filesize($directory.$template.'.blade.php'));
// fclose($handle);
// $directory = $path2[0].DIRECTORY_SEPARATOR.'emails'.DIRECTORY_SEPARATOR.$status->template.DIRECTORY_SEPARATOR;
//
// $handle = fopen($directory.$template.'.blade.php', 'r');
// $contents = fread($handle, filesize($directory.$template.'.blade.php'));
// fclose($handle);
$template = TemplateType::where('name', '=', $template)->first();
$template = TemplateType::where('name', '=', $template)->first();
$set = \App\Model\Common\TemplateSet::where('name', '=', $status->template)->first();
$set = \App\Model\Common\TemplateSet::where('name', '=', $status->template)->first();
if (isset($set['id'])) {
$template_data = \App\Model\Common\Template::where('set_id', '=', $set->id)->where('type', '=', $template->id)->first();
$contents = $template_data->message;
if ($template_data->variable == 1) {
if ($template_data->subject) {
$subject = $template_data->subject;
if ($ticket_number != null) {
$subject = $subject.' [#'.$ticket_number.']';
if (isset($set['id'])) {
$template_data = \App\Model\Common\Template::where('set_id', '=', $set->id)->where('type', '=', $template->id)->first();
$contents = $template_data->message;
if ($template_data->variable == 1) {
if ($template_data->subject) {
$subject = $template_data->subject;
if ($ticket_number != null) {
$subject = $subject . ' [#' . $ticket_number . ']';
}
} else {
$subject = $message['subject'];
}
} else {
$subject = $message['subject'];
}
} else {
$subject = $message['subject'];
$contents = null;
$subject = null;
}
} else {
$contents = null;
$subject = null;
}
$variables = ['{!!$user!!}', '{!!$agent!!}', '{!!$ticket_number!!}', '{!!$content!!}', '{!!$from!!}', '{!!$ticket_agent_name!!}', '{!!$ticket_client_name!!}', '{!!$ticket_client_email!!}', '{!!$ticket_body!!}', '{!!$ticket_assigner!!}', '{!!$ticket_link_with_number!!}', '{!!$system_error!!}', '{!!$agent_sign!!}', '{!!$department_sign!!}', '{!!$password_reset_link!!}', '{!!$email_address!!}', '{!!$user_password!!}', '{!!$system_from!!}', '{!!$system_link!!}'];
$variables = ['{!!$user!!}', '{!!$agent!!}', '{!!$ticket_number!!}', '{!!$content!!}', '{!!$from!!}', '{!!$ticket_agent_name!!}', '{!!$ticket_client_name!!}', '{!!$ticket_client_email!!}', '{!!$ticket_body!!}', '{!!$ticket_assigner!!}', '{!!$ticket_link_with_number!!}', '{!!$system_error!!}', '{!!$agent_sign!!}', '{!!$department_sign!!}', '{!!$password_reset_link!!}', '{!!$email_address!!}', '{!!$user_password!!}', '{!!$system_from!!}', '{!!$system_link!!}'];
$data = [$user, $agent, $ticket_number, $content, $from, $ticket_agent_name, $ticket_client_name, $ticket_client_email, $ticket_body, $ticket_assigner, $ticket_link_with_number, $system_error, $agent_sign, $department_sign, $password_reset_link, $email_address, $user_password, $system_from, $system_link];
$data = [$user, $agent, $ticket_number, $content, $from, $ticket_agent_name, $ticket_client_name, $ticket_client_email, $ticket_body, $ticket_assigner, $ticket_link_with_number, $system_error, $agent_sign, $department_sign, $password_reset_link, $email_address, $user_password, $system_from, $system_link];
// dd($variables,$data,$contents);
// $messagebody = str_replace($variables, $data, $contents);
// dd($variables,$data,$contents);
// $messagebody = str_replace($variables, $data, $contents);
foreach ($variables as $key => $variable) {
$messagebody = str_replace($variables[$key], $data[$key], $contents);
// dd($messagebody);
$contents = $messagebody;
}
foreach ($variables as $key => $variable) {
$messagebody = str_replace($variables[$key], $data[$key], $contents);
// dd($messagebody);
$contents = $messagebody;
}
// dd($messagebody);
//$mail->SMTPDebug = 3; // Enable verbose debug output
if ($protocol == 'smtp') {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $username; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = $smtpsecure; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port; // TCP port to connect to
$mail->setFrom($username, $fromname);
} elseif ($protocol == 'mail') {
$mail->IsSendmail(); // telling the class to use SendMail transport
if ($username == $fromname) {
$mail->setFrom($username);
} else {
//$mail->SMTPDebug = 3; // Enable verbose debug output
if ($protocol == 'smtp') {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $username; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = $smtpsecure; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port; // TCP port to connect to
$mail->setFrom($username, $fromname);
} elseif ($protocol == 'mail') {
$mail->IsSendmail(); // telling the class to use SendMail transport
if ($username == $fromname) {
$mail->setFrom($username);
} else {
$mail->setFrom($username, $fromname);
}
}
$mail->addAddress($recipants); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
if ($cc != null) {
foreach ($cc as $collaborator) {
//mail to collaborators
$collab_user_id = $collaborator->user_id;
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
$collab_email = $user_id_collab->email;
$mail->addCC($collab_email);
}
}
if ($attachment != null) {
$size = count($message['attachments']);
$attach = $message['attachments'];
for ($i = 0; $i < $size; $i++) {
$file_path = $attach[$i]->getRealPath();
$file_name = $attach[$i]->getClientOriginalName();
$mail->addAttachment($file_path, $file_name);
}
}
$mail->CharSet = "utf8";
$mail->Subject = $subject;
if ($template == 'ticket-reply-agent') {
$line = '---Reply above this line--- <br/><br/>';
$body = $line . $messagebody;
} else {
$body = $messagebody;
}
$rtl = CommonSettings::where('option_name', '=', 'enable_rtl')->first();
if($rtl->option_value == 1) {
$mail->ContentType = 'text/html';
$body = '<html dir="rtl" xml:lang="ar" lang="ar"><head></head><body dir="rtl">' . $body . '</body></html>';
} else {
}
$mail->Body = nl2br($body);
if (!$mail->send()) {
return;
} else {
return 1;
}
}
$mail->addAddress($recipants); // Add a recipient
// Name is optional
// $mail->addReplyTo('sada059@gmail.com', 'Information');
// Optional name
$mail->isHTML(true); // Set email format to HTML
if ($cc != null) {
foreach ($cc as $collaborator) {
//mail to collaborators
$collab_user_id = $collaborator->user_id;
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
$collab_email = $user_id_collab->email;
$mail->addCC($collab_email);
}
}
// $mail->addBCC($bc);
if ($attachment != null) {
$size = count($message['attachments']);
$attach = $message['attachments'];
for ($i = 0; $i < $size; $i++) {
$file_path = $attach[$i]->getRealPath();
$file_name = $attach[$i]->getClientOriginalName();
$mail->addAttachment($file_path, $file_name);
}
}
$mail->Subject = utf8_decode($subject);
if ($template == 'ticket-reply-agent') {
$line = '---Reply above this line--- <br/><br/>';
$mail->Body = utf8_decode($line.$messagebody);
} else {
$mail->Body = utf8_decode($messagebody);
}
// $mail->AltBody = $altbody;
if (!$mail->send()) {
return;
// echo 'Message could not be sent.';
// echo 'Mailer Error: '.$mail->ErrorInfo;
} else {
return 1;
// echo 'Message has been sent';
}
}
}
/**
@@ -295,123 +291,129 @@ class PhpMailController extends Controller
*
* @return MailNotification
*/
public function sendEmail($from, $to, $message)
{
$from_address = $this->fetch_smtp_details($from);
public function sendEmail($from, $to, $message) {
try {
$from_address = $this->fetch_smtp_details($from);
if ($from_address == null) {
return $from_address;
} else {
$username = $from_address->email_address;
$fromname = $from_address->email_name;
$password = \Crypt::decrypt($from_address->password);
$smtpsecure = $from_address->sending_encryption;
$host = $from_address->sending_host;
$port = $from_address->sending_port;
$protocol = $from_address->sending_protocol;
$username = $from_address->email_address;
$fromname = $from_address->email_name;
$password = \Crypt::decrypt($from_address->password);
$smtpsecure = $from_address->sending_encryption;
$host = $from_address->sending_host;
$port = $from_address->sending_port;
if (isset($to['email'])) {
$recipants = $to['email'];
} else {
$recipants = null;
}
if (isset($to['name'])) {
$recipantname = $to['name'];
} else {
$recipantname = null;
}
if (isset($to['cc'])) {
$cc = $to['cc'];
} else {
$cc = null;
}
if (isset($to['bc'])) {
$bc = $to['bc'];
} else {
$bc = null;
}
if (isset($message['subject'])) {
$subject = $message['subject'];
} else {
$subject = null;
}
if (isset($message['body'])) {
$content = $message['body'];
} else {
$content = null;
}
if (isset($message['scenario'])) {
$template = $message['scenario'];
} else {
$template = null;
}
if (isset($message['attachments'])) {
$attachment = $message['attachments'];
} else {
$attachment = null;
}
if (isset($to['email'])) {
$recipants = $to['email'];
} else {
$recipants = null;
}
if (isset($to['name'])) {
$recipantname = $to['name'];
} else {
$recipantname = null;
}
if (isset($to['cc'])) {
$cc = $to['cc'];
} else {
$cc = null;
}
if (isset($to['bc'])) {
$bc = $to['bc'];
} else {
$bc = null;
}
if (isset($message['subject'])) {
$subject = $message['subject'];
} else {
$subject = null;
}
if (isset($message['body'])) {
$content = $message['body'];
} else {
$content = null;
}
if (isset($message['scenario'])) {
$template = $message['scenario'];
} else {
$template = null;
}
if (isset($message['attachments'])) {
$attachment = $message['attachments'];
} else {
$attachment = null;
}
// template variables
if (Auth::user()) {
$agent = Auth::user()->user_name;
} else {
$agent = null;
}
// template variables
if (Auth::user()) {
$agent = Auth::user()->user_name;
} else {
$agent = null;
}
$system_link = url('/');
$system_link = url('/');
$system_from = $this->company();
$system_from = $this->company();
$mail = new \PHPMailer();
$mail = new \PHPMailer();
$status = \DB::table('settings_email')->first();
$status = \DB::table('settings_email')->first();
// dd($messagebody);
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $username; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = $smtpsecure; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port; // TCP port to connect to
$mail->setFrom($username, $fromname);
$mail->addAddress($recipants); // Add a recipient
// Name is optional
// $mail->addReplyTo('sada059@gmail.com', 'Information');
// Optional name
$mail->isHTML(true); // Set email format to HTML
if ($cc != null) {
foreach ($cc as $collaborator) {
//mail to collaborators
$collab_user_id = $collaborator->user_id;
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
$collab_email = $user_id_collab->email;
$mail->addCC($collab_email);
// dd($messagebody);
//$mail->SMTPDebug = 3; // Enable verbose debug output
if ($protocol == 'smtp') {
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $host; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $username; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = $smtpsecure; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port; // TCP port to connect to
$mail->setFrom($username, $fromname);
} elseif ($protocol == 'mail') {
$mail->IsSendmail(); // telling the class to use SendMail transport
if ($username == $fromname) {
$mail->setFrom($username);
} else {
$mail->setFrom($username, $fromname);
}
}
$mail->addAddress($recipants); // Add a recipient
// Name is optional
// $mail->addReplyTo('sada059@gmail.com', 'Information');
// Optional name
$mail->isHTML(true); // Set email format to HTML
if ($cc != null) {
foreach ($cc as $collaborator) {
//mail to collaborators
$collab_user_id = $collaborator->user_id;
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
$collab_email = $user_id_collab->email;
$mail->addCC($collab_email);
}
}
if ($attachment != null) {
$size = count($message['attachments']);
$attach = $message['attachments'];
for ($i = 0; $i < $size; $i++) {
$file_path = $attach[$i]->getRealPath();
$file_name = $attach[$i]->getClientOriginalName();
$mail->addAttachment($file_path, $file_name);
}
}
$mail->CharSet = "utf8";
$mail->Subject = $subject;
$mail->Body = $content;
if (!$mail->send()) {
} else {
}
}
}
$mail->addBCC($bc);
if ($attachment != null) {
$size = count($message['attachments']);
$attach = $message['attachments'];
for ($i = 0; $i < $size; $i++) {
$file_path = $attach[$i]->getRealPath();
$file_name = $attach[$i]->getClientOriginalName();
$mail->addAttachment($file_path, $file_name);
}
}
$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($content);
// $mail->AltBody = $altbody;
if (!$mail->send()) {
// echo 'Message could not be sent.';
// echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
// echo 'Message has been sent';
} catch (Exception $e) {
if($e instanceof ErrorException) {
return \Lang::get('lang.outgoing_email_failed');
}
}
}
@@ -420,8 +422,7 @@ class PhpMailController extends Controller
*
* @return type
*/
public function company()
{
public function company() {
$company = Company::Where('id', '=', '1')->first();
if ($company->company_name == null) {
$company = 'Support Center';
@@ -440,8 +441,7 @@ class PhpMailController extends Controller
*
* @return type integer
*/
public function mailfrom($reg, $dept_id)
{
public function mailfrom($reg, $dept_id) {
$email = Email::where('id', '=', '1')->first();
if ($reg == 1) {
return $email->sys_email;
@@ -454,4 +454,5 @@ class PhpMailController extends Controller
}
}
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers\Common;
// Controllers
use App\Http\Controllers\Controller;
// Requests
use Illuminate\Http\Request;
// Models
use App\User;
// classes
use LaravelFCM\Message\PayloadNotificationBuilder;
use LaravelFCM\Message\Topics;
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Response\DownstreamResponse;
use FCM;
use FCMGroup;
/**
* **********************************************
* PushNotificationController
* **********************************************
* This controller is used to send notification to FCM cloud which later will
* foreward notification to Mobile Application
*
* @author Ladybird <info@ladybirdweb.com>
*/
class PushNotificationController extends Controller {
public function response($token, User $user) {
}
/**
* function to get the fcm token from the api under a user.
* @param \Illuminate\Http\Request $request
* @return type
*/
public function fcmToken(Request $request, User $user) {
}
}

View File

@@ -27,25 +27,16 @@ use Lang;
* ***************************
* Controller to keep smtp details and fetch where ever needed.
*/
class SettingsController extends Controller
{
class SettingsController extends Controller {
/**
* Create a new controller instance.
*
* @return type void
*/
public function __construct()
{
// $this->smtp();
public function __construct() {
$this->middleware('auth');
$this->middleware('roles');
// self::driver();
// self::host();
// self::port();
// self::from();
// self::encryption();
// self::username();
// self::password();
}
/**
@@ -53,8 +44,7 @@ class SettingsController extends Controller
*
* @return response
*/
public function widgets()
{
public function widgets() {
return view('themes.default1.admin.helpdesk.theme.widgets');
}
@@ -63,8 +53,7 @@ class SettingsController extends Controller
*
* @return response
*/
public function list_widget()
{
public function list_widget() {
return \Datatable::collection(Widgets::where('id', '<', '7')->get())
->searchColumns('name')
->orderColumns('name', 'title', 'value')
@@ -78,33 +67,33 @@ class SettingsController extends Controller
return $model->value;
})
->addColumn('Actions', function ($model) {
return '<span data-toggle="modal" data-target="#edit_widget'.$model->id.'"><a class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a></span>
<div class="modal fade" id="edit_widget'.$model->id.'">
return '<span data-toggle="modal" data-target="#edit_widget' . $model->id . '"><a class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a></span>
<div class="modal fade" id="edit_widget' . $model->id . '">
<div class="modal-dialog">
<div class="modal-content">
<form action="'.url('edit-widget/'.$model->id).'" method="POST">
<form action="' . url('edit-widget/' . $model->id) . '" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">'.strtoupper($model->name).' </h4>
<h4 class="modal-title">' . strtoupper($model->name) . ' </h4>
</div>
<div class="modal-body">
<div class="form-group" style="width:100%">
<label>'.\Lang::get('lang.title').'</label><br/>
<input type="text" name="title" value="'.$model->title.'" class="form-control" style="width:100%">
<label>' . \Lang::get('lang.title') . '</label><br/>
<input type="text" name="title" value="' . $model->title . '" class="form-control" style="width:100%">
</div>
<br/>
<div class="form-group" style="width:100%">
<label>'.\Lang::get('lang.content').'</label><br/>
<textarea name="content" class="form-control" style="width:100%" id="Content'.$model->id.'">'.$model->value.'</textarea>
<label>' . \Lang::get('lang.content') . '</label><br/>
<textarea name="content" class="form-control" style="width:100%" id="Content' . $model->id . '">' . $model->value . '</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">'.\Lang::get('lang.close').'</button>
<input type="submit" class="btn btn-primary" value="'.\Lang::get('lang.update').'">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">' . \Lang::get('lang.close') . '</button>
<input type="submit" class="btn btn-primary" value="' . \Lang::get('lang.update') . '">
</div>
<script>
$(function () {
$("#Content'.$model->id.'").wysihtml5();
$("#Content' . $model->id . '").wysihtml5();
});
</script>
</form>
@@ -123,15 +112,13 @@ class SettingsController extends Controller
*
* @return type response
*/
public function edit_widget($id, Widgets $widgets, Request $request)
{
public function edit_widget($id, Widgets $widgets, Request $request) {
$widget = $widgets->where('id', '=', $id)->first();
$widget->title = $request->title;
$widget->value = $request->content;
try {
$widget->save();
return redirect()->back()->with('success', $widget->name.Lang::get('lang.saved_successfully'));
return redirect()->back()->with('success', $widget->name . Lang::get('lang.saved_successfully'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
@@ -142,8 +129,7 @@ class SettingsController extends Controller
*
* @return response
*/
public function social_buttons()
{
public function social_buttons() {
return view('themes.default1.admin.helpdesk.theme.social');
}
@@ -152,8 +138,7 @@ class SettingsController extends Controller
*
* @return response
*/
public function list_social_buttons()
{
public function list_social_buttons() {
return \Datatable::collection(Widgets::where('id', '>', '6')->get())
->searchColumns('name')
->orderColumns('name', 'value')
@@ -164,25 +149,25 @@ class SettingsController extends Controller
return $model->value;
})
->addColumn('Actions', function ($model) {
return '<span data-toggle="modal" data-target="#edit_widget'.$model->id.'"><a class="btn btn-warning btn-xs">'.\Lang::get('lang.edit').'</a></span>
<div class="modal fade" id="edit_widget'.$model->id.'">
return '<span data-toggle="modal" data-target="#edit_widget' . $model->id . '"><a class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a></span>
<div class="modal fade" id="edit_widget' . $model->id . '">
<div class="modal-dialog">
<div class="modal-content">
<form action="'.url('edit-widget/'.$model->id).'" method="POST">
<form action="' . url('edit-widget/' . $model->id) . '" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">'.strtoupper($model->name).' </h4>
<h4 class="modal-title">' . strtoupper($model->name) . ' </h4>
</div>
<div class="modal-body">
<br/>
<div class="form-group" style="width:100%">
<label>'.\Lang::get('lang.link').'</label><br/>
<input type="url" name="content" class="form-control" style="width:100%" value="'.$model->value.'">
<label>' . \Lang::get('lang.link') . '</label><br/>
<input type="url" name="content" class="form-control" style="width:100%" value="' . $model->value . '">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">'.\Lang::get('lang.close').'</button>
<input type="submit" class="btn btn-primary" value="'.\Lang::get('lang.update').'">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">' . \Lang::get('lang.close') . '</button>
<input type="submit" class="btn btn-primary" value="' . \Lang::get('lang.update') . '">
</div>
</form>
</div>
@@ -200,116 +185,26 @@ class SettingsController extends Controller
*
* @return type response
*/
public function edit_social_buttons($id, Widgets $widgets, Request $request)
{
public function edit_social_buttons($id, Widgets $widgets, Request $request) {
$widget = $widgets->where('id', '=', $id)->first();
$widget->title = $request->title;
$widget->value = $request->content;
try {
$widget->save();
return redirect()->back()->with('success', $widget->name.' Saved Successfully');
return redirect()->back()->with('success', $widget->name . ' Saved Successfully');
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
}
}
/**
* Driver.
*
* @return type void
*/
public static function driver()
{
$set = new Smtp();
$settings = Smtp::where('id', '=', '1')->first();
Config::set('mail.host', $settings->driver);
}
/**
* SMTP host.
*
* @return type void
*/
public static function host()
{
$set = new Smtp();
$settings = Smtp::where('id', '=', '1')->first();
Config::set('mail.host', $settings->host);
}
/**
* SMTP port.
*
* @return type void
*/
public static function port()
{
$set = new Smtp();
$settings = Smtp::where('id', '=', '1')->first();
Config::set('mail.port', intval($settings->port));
}
/**
* SMTP from.
*
* @return type void
*/
public static function from()
{
$set = new Smtp();
$settings = Smtp::where('id', '=', '1')->first();
Config::set('mail.from', ['address' => $settings->email, 'name' => $settings->company_name]);
}
/**
* SMTP encryption.
*
* @return type void
*/
public static function encryption()
{
$set = new Smtp();
$settings = Smtp::where('id', '=', '1')->first();
Config::set('mail.encryption', $settings->encryption);
}
/**
* SMTP username.
*
* @return type void
*/
public static function username()
{
$set = new Smtp();
$settings = Smtp::where('id', '=', '1')->first();
Config::set('mail.username', $settings->email);
}
/**
* SMTP password.
*
* @return type void
*/
public static function password()
{
$settings = Smtp::first();
if ($settings->password) {
$pass = $settings->password;
$password = Crypt::decrypt($pass);
Config::set('mail.password', $password);
}
}
/**
* get SMTP.
*
* @return type view
*/
public function getsmtp()
{
public function getsmtp() {
$settings = Smtp::where('id', '=', '1')->first();
return view('themes.default1.admin.helpdesk.emails.smtp', compact('settings'));
}
@@ -318,8 +213,7 @@ class SettingsController extends Controller
*
* @return type view
*/
public function postsmtp(SmtpRequest $request)
{
public function postsmtp(SmtpRequest $request) {
$data = Smtp::where('id', '=', 1)->first();
$data->driver = $request->input('driver');
$data->host = $request->input('host');
@@ -330,47 +224,12 @@ class SettingsController extends Controller
$data->password = Crypt::encrypt($request->input('password'));
try {
$data->save();
return \Redirect::route('getsmtp')->with('success', 'success');
} catch (Exception $e) {
return \Redirect::route('getsmtp')->with('fails', $e->errorInfo[2]);
}
}
/**
* SMTP.
*
* @return type void
*/
public static function smtp()
{
$settings = Smtp::where('id', '=', '1')->first();
if ($settings->password) {
$password = Crypt::decrypt($settings->password);
Config::set('mail.driver', $settings->driver);
Config::set('mail.password', $password);
Config::set('mail.username', $settings->email);
Config::set('mail.encryption', $settings->encryption);
Config::set('mail.from', ['address' => $settings->email, 'name' => $settings->name]);
Config::set('mail.port', intval($settings->port));
Config::set('mail.host', $settings->host);
}
}
/**
* Settings.
*
* @param type Smtp $set
*
* @return type view\
*/
public function settings(Smtp $set)
{
$settings = $set->where('id', '1')->first();
return view('themes.default1.admin.settings', compact('settings'));
}
/**
* Post settings.
*
@@ -379,8 +238,7 @@ class SettingsController extends Controller
*
* @return type view
*/
public function PostSettings(Settings $set, Request $request)
{
public function PostSettings(Settings $set, Request $request) {
$settings = $set->where('id', '1')->first();
$pass = $request->input('password');
$password = Crypt::encrypt($pass);
@@ -393,7 +251,7 @@ class SettingsController extends Controller
if (Input::file('logo')) {
$name = Input::file('logo')->getClientOriginalName();
$destinationPath = 'dist/logo';
$fileName = rand(0000, 9999).'.'.$name;
$fileName = rand(0000, 9999) . '.' . $name;
Input::file('logo')->move($destinationPath, $fileName);
$settings->logo = $fileName;
$settings->save();
@@ -407,60 +265,11 @@ class SettingsController extends Controller
}
}
/**
* version_check.
*
* @return type
*/
public function version_check()
{
$response_url = \URL::route('post-version-check');
echo "<form action='http://www.faveohelpdesk.com/billing/public/version' method='post' name='redirect'>";
echo "<input type='hidden' name='_token' value='csrf_token()'/>";
echo "<input type='hidden' name='title' value='Faveo helpdesk community'/>";
echo "<input type='hidden' name='response_url' value='".$response_url."' />";
echo '</form>';
echo "<script language='javascript'>document.redirect.submit();</script>";
}
/**
* post_version_check.
*
* @return type
*/
public function post_version_check(Request $request)
{
// dd($request);
$current_version = \Config::get('app.version');
$current_version = explode(' ', $current_version);
$current_version = $current_version[1];
$new_version = $request->value;
if ($current_version == $new_version) {
return redirect()->route('checkupdate')->with('info', ' No, new Updates');
} elseif ($current_version < $new_version) {
$version = Version_Check::where('id', '=', '1')->first();
$version->current_version = $current_version;
$version->new_version = $new_version;
$version->save();
return redirect()->route('checkupdate')->with('info', ' Version '.$new_version.' is Available');
} else {
return redirect()->route('checkupdate')->with('info', ' Error Checking Version');
}
}
public function getupdate()
{
return \View::make('themes.default1.admin.helpdesk.settings.checkupdate');
}
public function Plugins()
{
public function Plugins() {
return view('themes.default1.admin.helpdesk.settings.plugins');
}
public function GetPlugin()
{
public function GetPlugin() {
$plugins = $this->fetchConfig();
return \Datatable::collection(new Collection($plugins))
@@ -468,15 +277,15 @@ class SettingsController extends Controller
->addColumn('name', function ($model) {
if (array_has($model, 'path')) {
if ($model['status'] == 0) {
$activate = '<a href='.url('plugin/status/'.$model['path']).'>Activate</a>';
$activate = '<a href=' . url('plugin/status/' . $model['path']) . '>Activate</a>';
$settings = ' ';
} else {
$settings = '<a href='.url($model['settings']).'>Settings</a> | ';
$activate = '<a href='.url('plugin/status/'.$model['path']).'>Deactivate</a>';
$settings = '<a href=' . url($model['settings']) . '>Settings</a> | ';
$activate = '<a href=' . url('plugin/status/' . $model['path']) . '>Deactivate</a>';
}
$delete = '<a href= id=delete'.$model['path'].' data-toggle=modal data-target=#del'.$model['path']."><span style='color:red'>Delete</span></a>"
."<div class='modal fade' id=del".$model['path'].">
$delete = '<a href="#" id=delete' . $model['path'] . ' data-toggle=modal data-target=#del' . $model['path'] . "><span style='color:red'>Delete</span></a>"
. "<div class='modal fade' id=del" . $model['path'] . ">
<div class='modal-dialog'>
<div class=modal-content>
<div class=modal-header>
@@ -485,8 +294,8 @@ class SettingsController extends Controller
<div class=modal-body>
<p>Are you Sure ?</p>
<div class=modal-footer>
<button type=button class='btn btn-default pull-left' data-dismiss=modal id=dismis>".\Lang::get('lang.close').'</button>
<a href='.url('plugin/delete/'.$model['path'])."><button class='btn btn-danger'>Delete</button></a>
<button type=button class='btn btn-default pull-left' data-dismiss=modal id=dismis>" . \Lang::get('lang.close') . '</button>
<a href=' . url('plugin/delete/' . $model['path']) . "><button class='btn btn-danger'>Delete</button></a>
</div>
@@ -494,12 +303,12 @@ class SettingsController extends Controller
</div>
</div>
</div>";
$action = '<br><br>'.$delete.' | '.$settings.$activate;
$action = '<br><br>' . $delete . ' | ' . $settings . $activate;
} else {
$action = '';
}
return ucfirst($model['name']).$action;
return ucfirst($model['name']) . $action;
})
->addColumn('description', function ($model) {
return ucfirst($model['description']);
@@ -508,7 +317,7 @@ class SettingsController extends Controller
return ucfirst($model['author']);
})
->addColumn('website', function ($model) {
return '<a href='.$model['website'].' target=_blank>'.$model['website'].'</a>';
return '<a href=' . $model['website'] . ' target=_blank>' . $model['website'] . '</a>';
})
->addColumn('version', function ($model) {
return $model['version'];
@@ -521,9 +330,8 @@ class SettingsController extends Controller
*
* @return type
*/
public function ReadPlugins()
{
$dir = app_path().DIRECTORY_SEPARATOR.'Plugins';
public function ReadPlugins() {
$dir = app_path() . DIRECTORY_SEPARATOR . 'Plugins';
$plugins = array_diff(scandir($dir), ['.', '..']);
return $plugins;
@@ -536,76 +344,85 @@ class SettingsController extends Controller
*
* @return type
*/
public function PostPlugins(Request $request)
{
$v = $this->validate($request, ['plugin' => 'required|mimes:application/zip,zip,Zip']);
$plug = new Plugin();
$file = $request->file('plugin');
//dd($file);
$destination = app_path().DIRECTORY_SEPARATOR.'Plugins';
$zipfile = $file->getRealPath();
/*
* get the file name and remove .zip
*/
$filename2 = $file->getClientOriginalName();
$filename2 = str_replace('.zip', '', $filename2);
$filename1 = ucfirst($file->getClientOriginalName());
$filename = str_replace('.zip', '', $filename1);
mkdir($destination.DIRECTORY_SEPARATOR.$filename);
/*
* extract the zip file using zipper
*/
\Zipper::make($zipfile)->folder($filename2)->extractTo($destination.DIRECTORY_SEPARATOR.$filename);
public function PostPlugins(Request $request) {
$this->validate($request, ['plugin' => 'required|mimes:application/zip,zip,Zip']);
try {
if (!extension_loaded('zip')){
throw new Exception('Please enable zip extension in your php');
}
$plug = new Plugin();
$file = $request->file('plugin');
$destination = app_path() . DIRECTORY_SEPARATOR . 'Plugins';
$zipfile = $file->getRealPath();
/*
* get the file name and remove .zip
*/
$filename2 = $file->getClientOriginalName();
$filename2 = str_replace('.zip', '', $filename2);
$filename1 = ucfirst($file->getClientOriginalName());
$filename = str_replace('.zip', '', $filename1);
$dir_check = scandir($destination);
if (in_array($filename, $dir_check)) {
return redirect()->back()->with('fails', Lang::get('lang.plugin-exists'));
}
mkdir($destination . DIRECTORY_SEPARATOR . $filename);
/*
* extract the zip file using zipper
*/
\Zipper::make($zipfile)->folder($filename2)->extractTo($destination . DIRECTORY_SEPARATOR . $filename);
$file = app_path().DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR.$filename; // Plugin file path
$file = app_path() . DIRECTORY_SEPARATOR . 'Plugins' . DIRECTORY_SEPARATOR . $filename; // Plugin file path
if (file_exists($file)) {
$seviceporvider = $file.DIRECTORY_SEPARATOR.'ServiceProvider.php';
$config = $file.DIRECTORY_SEPARATOR.'config.php';
if (file_exists($seviceporvider) && file_exists($config)) {
/*
* move to faveo config
*/
$faveoconfig = config_path().DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$filename.'.php';
if ($faveoconfig) {
//copy($config, $faveoconfig);
if (file_exists($file)) {
$seviceporvider = $file . DIRECTORY_SEPARATOR . 'ServiceProvider.php';
$config = $file . DIRECTORY_SEPARATOR . 'config.php';
if (file_exists($seviceporvider) && file_exists($config)) {
/*
* write provider list in app.php line 128
* move to faveo config
*/
$app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
chmod($app, 0644);
$str = "\n\n\t\t\t'App\\Plugins\\$filename"."\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
file_put_contents($app, implode("\n", $lines));
$plug->create(['name' => $filename, 'path' => $filename, 'status' => 1]);
$faveoconfig = config_path() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $filename . '.php';
if ($faveoconfig) {
return redirect()->back()->with('success', 'Installed SuccessFully');
//copy($config, $faveoconfig);
/*
* write provider list in app.php line 128
*/
$app = base_path() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'app.php';
chmod($app, 0644);
$str = "\n\n\t\t\t'App\\Plugins\\$filename" . "\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
file_put_contents($app, implode("\n", $lines));
$plug->create(['name' => $filename, 'path' => $filename, 'status' => 1]);
return redirect()->back()->with('success', Lang::get('lang.plugin-installed'));
} else {
/*
* delete if the plugin hasn't config.php and ServiceProvider.php
*/
$this->deleteDirectory($file);
return redirect()->back()->with('fails', Lang::get('no-plugin-file') . $file);
}
} else {
/*
* delete if the plugin hasn't config.php and ServiceProvider.php
*/
$this->deleteDirectory($file);
return redirect()->back()->with('fails', 'Their is no '.$file);
return redirect()->back()->with('fails', Lang::get('plugin-config-missing') . $file);
}
} else {
/*
* delete if the plugin hasn't config.php and ServiceProvider.php
* delete if the plugin Name is not equal to the folder name
*/
$this->deleteDirectory($file);
return redirect()->back()->with('fails', 'Their is no <b>config.php or ServiceProvider.php</b> '.$file);
return redirect()->back()->with('fails', '<b>' . Lang::get('lang.plugin-path-missing') . '</b> ' . $file);
}
} else {
/*
* delete if the plugin Name is not equal to the folder name
*/
$this->deleteDirectory($file);
return redirect()->back()->with('fails', '<b>Plugin File Path is not exist</b> '.$file);
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
@@ -616,8 +433,7 @@ class SettingsController extends Controller
*
* @return bool
*/
public function deleteDirectory($dir)
{
public function deleteDirectory($dir) {
if (!file_exists($dir)) {
return true;
}
@@ -628,8 +444,8 @@ class SettingsController extends Controller
if ($item == '.' || $item == '..') {
continue;
}
chmod($dir.DIRECTORY_SEPARATOR.$item, 0777);
if (!$this->deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
chmod($dir . DIRECTORY_SEPARATOR . $item, 0777);
if (!$this->deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
@@ -638,9 +454,8 @@ class SettingsController extends Controller
return rmdir($dir);
}
public function ReadConfigs()
{
$dir = app_path().DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR;
public function ReadConfigs() {
$dir = app_path() . DIRECTORY_SEPARATOR . 'Plugins' . DIRECTORY_SEPARATOR;
$directories = scandir($dir);
$files = [];
foreach ($directories as $key => $file) {
@@ -648,7 +463,7 @@ class SettingsController extends Controller
continue;
}
if (is_dir($dir.DIRECTORY_SEPARATOR.$file)) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
$files[$key] = $file;
}
}
@@ -657,7 +472,7 @@ class SettingsController extends Controller
$plugins = [];
if (count($files) > 0) {
foreach ($files as $key => $file) {
$plugin = $dir.$file;
$plugin = $dir . $file;
$plugins[$key] = array_diff(scandir($plugin), ['.', '..', 'ServiceProvider.php']);
$plugins[$key]['file'] = $plugin;
}
@@ -667,7 +482,7 @@ class SettingsController extends Controller
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == 'config.php') {
$config[] = $dir.DIRECTORY_SEPARATOR.$file;
$config[] = $dir . DIRECTORY_SEPARATOR . $file;
}
}
closedir($dh);
@@ -680,8 +495,7 @@ class SettingsController extends Controller
}
}
public function fetchConfig()
{
public function fetchConfig() {
$configs = $this->ReadConfigs();
//dd($configs);
$plugs = new Plugin();
@@ -717,15 +531,14 @@ class SettingsController extends Controller
return $attributes;
}
public function DeletePlugin($slug)
{
$dir = app_path().DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR.$slug;
public function DeletePlugin($slug) {
$dir = app_path() . DIRECTORY_SEPARATOR . 'Plugins' . DIRECTORY_SEPARATOR . $slug;
$this->deleteDirectory($dir);
/*
* remove service provider from app.php
*/
$str = "'App\\Plugins\\$slug"."\\ServiceProvider',";
$path_to_file = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
$str = "'App\\Plugins\\$slug" . "\\ServiceProvider',";
$path_to_file = base_path() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'app.php';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace($str, '//', $file_contents);
file_put_contents($path_to_file, $file_contents);
@@ -738,13 +551,12 @@ class SettingsController extends Controller
return redirect()->back()->with('success', 'Deleted Successfully');
}
public function StatusPlugin($slug)
{
public function StatusPlugin($slug) {
$plugs = new Plugin();
$plug = $plugs->where('name', $slug)->first();
if (!$plug) {
$app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
$str = "\n'App\\Plugins\\$slug"."\\ServiceProvider',";
$app = base_path() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'app.php';
$str = "\n'App\\Plugins\\$slug" . "\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
@@ -757,8 +569,8 @@ class SettingsController extends Controller
if ($status == 0) {
$plug->status = 1;
$app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
$str = "\n'App\\Plugins\\$slug"."\\ServiceProvider',";
$app = base_path() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'app.php';
$str = "\n'App\\Plugins\\$slug" . "\\ServiceProvider',";
$line_i_am_looking_for = 144;
$lines = file($app, FILE_IGNORE_NEW_LINES);
$lines[$line_i_am_looking_for] = $str;
@@ -769,8 +581,8 @@ class SettingsController extends Controller
/*
* remove service provider from app.php
*/
$str = "\n'App\\Plugins\\$slug"."\\ServiceProvider',";
$path_to_file = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php';
$str = "\n'App\\Plugins\\$slug" . "\\ServiceProvider',";
$path_to_file = base_path() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'app.php';
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace($str, '//', $file_contents);

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Model\helpdesk\Ticket\Tickets;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
@@ -38,13 +39,6 @@ class HomeController extends Controller
return view('themes/default1/admin/dashboard');
}
public function getsmtp()
{
$smtp = \App\Model\helpdesk\Email\Smtp::where('id', '=', '1')->first();
return $smtp->host;
}
public function getdata()
{
return \View::make('emails/notifications/agent');

View File

@@ -9,69 +9,73 @@ use Artisan;
use Exception;
use Illuminate\Http\Request;
class UpgradeController extends Controller
{
class UpgradeController extends Controller {
public $dir;
public function __construct()
{
public function __construct() {
$dir = base_path();
$this->dir = $dir;
}
public function getLatestVersion()
{
$name = \Config::get('app.name');
//serial key should be encrypted data
$serial_key = Utility::encryptByFaveoPublicKey('O5Y647RJF8QHLDOE');
//order number should be encrypted data
$order_number = Utility::encryptByFaveoPublicKey('23540755');
$url = url('/');
//dd($url);
$post_data = [
'serial_key' => $serial_key,
'order_number' => $order_number,
'name' => $name,
'version' => Utility::getFileVersion(),
'request_type' => 'check_update',
'url' => $url,
];
$url = 'http://www.faveohelpdesk.com/billing/verification';
if (str_contains($url, ' ')) {
$url = str_replace(' ', '%20', $url);
}
$curl = $this->postCurl($url, $post_data);
//dd($curl);
if (is_array($curl)) {
if (array_key_exists('status', $curl)) {
if ($curl['status'] == 'success') {
if (array_key_exists('version', $curl)) {
return $curl['version'];
public function getLatestVersion() {
try {
$name = \Config::get('app.name');
//dd($name);
//serial key should be encrypted data
$serial_key = '64JAHF9WVJA4GCUZ';
//order number should be encrypted data
$order_number = '44596328';
$url = env('APP_URL');
$data = [
'serial_key' => $serial_key,
'order_number' => $order_number,
'name' => $name,
'version' => Utility::getFileVersion(),
'request_type' => 'check_update',
'url' => $url,
];
$data = Utility::encryptByFaveoPublicKey(json_encode($data));
//dd($data);
$post_data = [
'data' => $data
];
$url = 'http://faveohelpdesk.com/billing/public/verification';
if (str_contains($url, ' ')) {
$url = str_replace(' ', '%20', $url);
}
$curl = $this->postCurl($url, $post_data);
if (is_array($curl)) {
if (array_key_exists('status', $curl)) {
if ($curl['status'] == 'success') {
if (array_key_exists('version', $curl)) {
return $curl['version'];
}
}
}
}
} catch (\Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function downloadLatestCode()
{
public function downloadLatestCode() {
$name = \Config::get('app.name');
$url = 'http://www.faveohelpdesk.com/billing/download-url';
if (str_contains($url, ' ')) {
$url = str_replace(' ', '%20', $url);
$durl = 'http://www.faveohelpdesk.com/billing/public/download-url';
if (str_contains($durl, ' ')) {
$durl = str_replace(' ', '%20', $durl);
}
$data = [
'name' => $name,
];
$download = $this->postCurl($url, $data);
$download = $this->postDownloadCurl($durl, $data);
$url = $download['zipball_url'];
$download_url = $download['zipball_url'];
return $url;
return $download_url;
}
public function saveLatestCodeAtTemp($download_url)
{
public function saveLatestCodeAtTemp($download_url) {
echo '<p>Downloading New Update</p>';
$context = stream_context_create(
[
@@ -83,10 +87,10 @@ class UpgradeController extends Controller
$newUpdate = file_get_contents($download_url, false, $context);
if (!is_dir("$this->dir/UPDATES/")) {
\File::makeDirectory($this->dir.'/UPDATES/', 0777);
\File::makeDirectory($this->dir . '/UPDATES/', 0777);
}
$dlHandler = fopen($this->dir.'/UPDATES/'.'/faveo-helpdesk-master.zip', 'w');
$dlHandler = fopen($this->dir . '/UPDATES/' . '/faveo-helpdesk-master.zip', 'w');
if (!fwrite($dlHandler, $newUpdate)) {
echo '<p>Could not save new update. Operation aborted.</p>';
exit();
@@ -95,85 +99,108 @@ class UpgradeController extends Controller
echo '<p>Update Downloaded And Saved</p>';
}
public function doUpdate()
{
Artisan::call('down');
$update = $this->dir.'/UPDATES';
//Open The File And Do Stuff
$zipHandle = zip_open($update.'/faveo-helpdesk-master.zip');
//dd($update . '/faveo-' . $aV . '.zip');
echo '<ul class=list-unstyled>';
while ($aF = zip_read($zipHandle)) {
$thisFileName = zip_entry_name($aF);
$thisFileDir = dirname($thisFileName);
//Continue if its not a file
if (substr($thisFileName, -1, 1) == '/') {
continue;
public function doUpdate() {
try {
$memory_limit = ini_get('memory_limit');
if ($memory_limit < 256) {
echo '<ul class=list-unstyled>';
echo "<li style='color:red;'>Sorry we can not process your request because of limited memory! You have only $memory_limit. For this you need atleast 256 MB</li>";
echo '</ul>';
return 0;
}
//Make the directory if we need to...
if (!is_dir($update.'/'.$thisFileDir.'/')) {
\File::makeDirectory($update.'/'.$thisFileDir, 0775, true, true);
// mkdir($update.'/'. $thisFileDir, 0775);
echo '<li style="color:white;">Created Directory '.$thisFileDir.'</li>';
if (!extension_loaded('zip')) {
echo '<ul class=list-unstyled>';
echo "<li style='color:red;'>Sorry we can not process your request because you don't have ZIP extension contact your system admin</li>";
echo '</ul>';
return 0;
}
//Artisan::call('down');
$update = $this->dir . '/UPDATES';
//Open The File And Do Stuff
$zipHandle = zip_open($update . '/faveo-helpdesk-master.zip');
//dd($update . '/faveo-' . $aV . '.zip');
//Overwrite the file
if (!is_dir($update.'/'.$thisFileName)) {
echo '<li style="color:white;">'.$thisFileName.'...........';
$contents = zip_entry_read($aF, zip_entry_filesize($aF));
$contents = str_replace("\r\n", "\n", $contents);
$updateThis = '';
echo '<ul class=list-unstyled>';
while ($aF = zip_read($zipHandle)) {
$thisFileName = zip_entry_name($aF);
$thisFileDir = dirname($thisFileName);
//If we need to run commands, then do it.
if ($thisFileName == $thisFileDir.'/.env') {
if (is_file($update.'/'.$thisFileDir.'/.env')) {
unlink($update.'/'.$thisFileDir.'/.env');
unlink($update.'/'.$thisFileDir.'/config/database.php');
//Continue if its not a file
if (substr($thisFileName, -1, 1) == '/') {
continue;
}
//Make the directory if we need to...
if (!is_dir($update . '/' . $thisFileDir . '/')) {
\File::makeDirectory($update . '/' . $thisFileDir, 0775, true, true);
// mkdir($update.'/'. $thisFileDir, 0775);
echo '<li style="color:white;">Created Directory ' . $thisFileDir . '</li>';
}
//Overwrite the file
if (!is_dir($update . '/' . $thisFileName)) {
echo '<li style="color:white;">' . $thisFileName . '...........';
$contents = zip_entry_read($aF, zip_entry_filesize($aF));
$contents = str_replace("\r\n", "\n", $contents);
$updateThis = '';
//If we need to run commands, then do it.
if ($thisFileName == $thisFileDir . '/.env') {
if (is_file($update . '/' . $thisFileDir . '/.env')) {
unlink($update . '/' . $thisFileDir . '/.env');
unlink($update . '/' . $thisFileDir . '/config/database.php');
}
echo' EXECUTED</li>';
} else {
$updateThis = fopen($update . '/' . $thisFileName, 'w');
fwrite($updateThis, $contents);
fclose($updateThis);
unset($contents);
echo' UPDATED</li>';
}
echo' EXECUTED</li>';
} else {
$updateThis = fopen($update.'/'.$thisFileName, 'w');
fwrite($updateThis, $contents);
fclose($updateThis);
unset($contents);
echo' UPDATED</li>';
}
}
echo '</ul>';
//Artisan::call('migrate', ['--force' => true]);
return true;
} catch (Exception $ex) {
echo '<ul class=list-unstyled>';
echo "<li style='color:red;'>" . $ex->getMessage() . "</li>";
echo '</ul>';
}
echo '</ul>';
Artisan::call('up');
return true;
}
public function copyToActualDirectory($latest_version)
{
$directory = "$this->dir/UPDATES";
$destination = $this->dir;
public function copyToActualDirectory($latest_version) {
try {
echo '<ul class=list-unstyled>';
$directory = "$this->dir/UPDATES";
$destination = $this->dir;
// $destination = "/Applications/AMPPS/www/test/new";
$directories = \File::directories($directory);
$directories = \File::directories($directory);
// echo "current directory => $directory <br>";
// echo "Destination Directory => $destination <br>";
foreach ($directories as $source) {
$success = \File::copyDirectory($source, $destination);
echo '<p class="success">&raquo; </p>';
foreach ($directories as $source) {
$success = \File::copyDirectory($source, $destination);
echo '<li class="success">&raquo; </li>';
}
\File::deleteDirectory($directory);
$this->deleteBarNotification('new-version');
echo "<li style='color:green;'>&raquo; Faveo Updated to v" . Utility::getFileVersion() . "</li>";
echo '</ul>';
} catch (Exception $ex) {
echo '<ul class=list-unstyled>';
echo "<li style='color:red;'>" . $ex->getMessage() . "</li>";
echo '</ul>';
}
\File::deleteDirectory($directory);
$this->deleteBarNotification('new-version');
echo '<p class="success">&raquo; Faveo Updated to v'.Utility::getFileVersion().'</p>';
exit();
}
public function deleteBarNotification($key)
{
public function deleteBarNotification($key) {
try {
$noti = new BarNotification();
$notifications = $noti->where('key', $key)->get();
@@ -185,45 +212,43 @@ class UpgradeController extends Controller
}
}
public function fileUpdate()
{
public function fileUpdate() {
try {
if (Utility::getFileVersion() < Utility::getDatabaseVersion()) {
$latest_version = $this->getLatestVersion();
if (Utility::getFileVersion() < $latest_version) {
$url = url('file-upgrade');
//$string = "Your Database is outdated please upgrade <a href=$url>Now !</a>";
return view('themes.default1.update.file', compact('url'));
} else {
return redirect()->back();
}
return redirect('dashboard')->with('fails', 'Could not find latest realeases from repository.');
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function fileUpgrading(Request $request)
{
public function fileUpgrading(Request $request) {
try {
if (Utility::getFileVersion() < Utility::getDatabaseVersion()) {
$latest_version = $this->getLatestVersion();
//dd($latest_version);
$current_version = Utility::getFileVersion();
if ($latest_version != '') {
$_this = new self();
//
$latest_version = $this->getLatestVersion();
return view('themes.default1.update.test', compact('latest_version', 'current_version', 'request'));
} else {
return redirect()->back()->with('fails', 'Could not find latest realeases from repository.');
$current_version = Utility::getFileVersion();
if ($latest_version != '') {
if (Utility::getFileVersion() < $latest_version) {
return view('themes.default1.update.update', compact('latest_version', 'current_version', 'request'));
}
} else {
return redirect()->back();
}
return redirect('dashboard')->with('fails', 'Could not find latest realeases from repository.');
// else {
// return redirect()->back();
// }
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function testScroll()
{
public function testScroll() {
$ex = 1000;
echo '<ul style=list-unstyled>';
for ($i = 0; $i < $ex; $i++) {
@@ -232,8 +257,7 @@ class UpgradeController extends Controller
echo '</ul>';
}
public function fileUpgrading1(Request $request)
{
public function fileUpgrading1(Request $request) {
if (Utility::getFileVersion() < Utility::getDatabaseVersion()) {
$latest_version = $this->getLatestVersion();
// dd($latest_version);
@@ -243,7 +267,7 @@ class UpgradeController extends Controller
echo "<p>CURRENT VERSION: $current_version</p>";
echo '<p>Reading Current Releases List</p>';
if ($latest_version > $current_version) {
echo '<p>New Update Found: v'.$latest_version.'</p>';
echo '<p>New Update Found: v' . $latest_version . '</p>';
$found = true;
if (!is_file("$this->dir/UPDATES/faveo-helpdesk-master.zip")) {
if ($request->get('dodownload') == true) {
@@ -254,7 +278,7 @@ class UpgradeController extends Controller
echo '<p>Error in you network connection.</p>';
}
} else {
echo '<p>Latest code found. <a href='.url('file-upgrade?dodownload=true').'>&raquo; Download Now?</a></p>';
echo '<p>Latest code found. <a href=' . url('file-upgrade?dodownload=true') . '>&raquo; Download Now?</a></p>';
exit();
}
} else {
@@ -263,7 +287,7 @@ class UpgradeController extends Controller
if ($request->get('doUpdate') == true) {
$updated = $this->doUpdate();
} else {
echo '<p>Update ready. <a href='.url('file-upgrade?doUpdate=true').'>&raquo; Install Now?</a></p>';
echo '<p>Update ready. <a href=' . url('file-upgrade?doUpdate=true') . '>&raquo; Install Now?</a></p>';
exit();
}
@@ -283,40 +307,73 @@ class UpgradeController extends Controller
}
}
public function getCurl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
if (curl_exec($ch) === false) {
echo 'Curl error: '.curl_error($ch);
}
$data = curl_exec($ch);
dd($data);
curl_close($ch);
public function getCurl($url) {
try {
$curl = Utility::_isCurl();
if (!$curl) {
throw new Exception("Please enable your curl function to check latest update");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
if (curl_exec($ch) === false) {
echo 'Curl error: ' . curl_error($ch);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
return $data;
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function postCurl($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
if (curl_exec($ch) === false) {
echo 'Curl error: '.curl_error($ch);
public function postDownloadCurl($url, $data) {
try {
$curl = Utility::_isCurl();
if (!$curl) {
throw new Exception("Please enable your curl function to check latest update");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
if (curl_exec($ch) === false) {
echo 'Curl error: ' . curl_error($ch);
}
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data, true);
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data, true);
}
public function databaseUpdate()
{
public function postCurl($url, $data) {
try {
$curl = Utility::_isCurl();
if (!$curl) {
throw new Exception("Please enable your curl function to check latest update");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
if (curl_exec($ch) === false) {
echo 'Curl error: ' . curl_error($ch);
}
$data = curl_exec($ch);
curl_close($ch);
$data = Utility::decryptByFaveoPrivateKey($data);
return json_decode($data, true);
} catch (Exception $ex) {
return redirect()->back()->with('fails', $ex->getMessage());
}
}
public function databaseUpdate() {
try {
if (Utility::getFileVersion() > Utility::getDatabaseVersion()) {
$url = url('database-upgrade');
@@ -330,8 +387,7 @@ class UpgradeController extends Controller
}
}
public function databaseUpgrade()
{
public function databaseUpgrade() {
try {
if (Utility::getFileVersion() > Utility::getDatabaseVersion()) {
Artisan::call('migrate', ['--force' => true]);
@@ -344,4 +400,5 @@ class UpgradeController extends Controller
return redirect()->back()->with('fails', $ex->getMessage());
}
}
}

View File

@@ -7,10 +7,9 @@ use Config;
use Exception;
use Schema;
class LibraryController extends Controller
{
public static function getFileVersion()
{
class LibraryController extends Controller {
public static function getFileVersion() {
try {
$app = Config::get('app.version');
if ($app) {
@@ -23,8 +22,7 @@ class LibraryController extends Controller
}
}
public static function getDatabaseVersion()
{
public static function getDatabaseVersion() {
try {
$database = self::isDatabaseSetup();
if ($database == true) {
@@ -41,8 +39,7 @@ class LibraryController extends Controller
}
}
public static function isDatabaseSetup()
{
public static function isDatabaseSetup() {
try {
if (Schema::hasTable('settings_system')) {
return true;
@@ -52,78 +49,47 @@ class LibraryController extends Controller
}
}
public static function encryptByFaveoPublicKey($plaintext)
{
public static function encryptByFaveoPublicKey($data) {
try {
// Compress the data to be sent
$plaintext = gzcompress($plaintext);
// Get the public Key of the recipient
$path = storage_path('app'.DIRECTORY_SEPARATOR.'faveo-public.key');
$key_content = file_get_contents($path);
$path = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public.key';
//dd($path);
$publicKey = openssl_pkey_get_public($key_content);
//dd($publicKey);
$a_key = openssl_pkey_get_details($publicKey);
// Encrypt the data in small chunks and then combine and send it.
$chunkSize = ceil($a_key['bits'] / 8) - 11;
$output = '';
while ($plaintext) {
$chunk = substr($plaintext, 0, $chunkSize);
$plaintext = substr($plaintext, $chunkSize);
$encrypted = '';
if (!openssl_public_encrypt($chunk, $encrypted, $publicKey)) {
throw new Exception('Failed to encrypt data');
}
$output .= $encrypted;
}
openssl_free_key($publicKey);
// This is the final encrypted data to be sent to the recipient
$encrypted = $output;
return $encrypted;
} catch (Exception $ex) {
dd($ex);
}
}
public static function decryptByFaveoPrivateKey($encrypted)
{
try {
//$encrypted = p¥Ùn¿olÓ¥9)OÞݸÔvh§=Ìtt1rkC‰É§%YœfÐS\BâkHW€mùÌØg¹+VŠ¥²?áÙ{/<¶¡£e¡ˆr°(V)Öíàr„Ž]K9¤ÿÖ¡Åmž”üÈoò״µºŽ06¼e €rœ['4çhH¾ö:¨œS„œ¦,|¤ÇqÂrÈŸd+ml‡ uötφûóŽ&áyÙ(ÆŒÁ$¥±Zj*îàÒöLˆD†aɐö_§è¶°·V„Þú]%ÅR*B=žéršæñ*i+፭±èç|c¹Ñߟ­F$;
// Get the private Key
$path = storage_path('app'.DIRECTORY_SEPARATOR.'faveo-private.key');
$key_content = file_get_contents($path);
if (!$privateKey = openssl_pkey_get_private($key_content)) {
die('Private Key failed');
}
$a_key = openssl_pkey_get_details($privateKey);
$public_key = openssl_get_publickey($key_content);
// Decrypt the data in the small chunks
$chunkSize = ceil($a_key['bits'] / 8);
$output = '';
$encrypted = $e = NULL;
openssl_seal($data, $encrypted, $e, array($public_key));
while ($encrypted) {
$chunk = substr($encrypted, 0, $chunkSize);
$encrypted = substr($encrypted, $chunkSize);
$decrypted = '';
if (!openssl_private_decrypt($chunk, $decrypted, $privateKey)) {
die('Failed to decrypt data');
}
$output .= $decrypted;
}
openssl_free_key($privateKey);
$sealed_data = base64_encode($encrypted);
$envelope = base64_encode($e[0]);
// Uncompress the unencrypted data.
$output = gzuncompress($output);
echo '<br /><br /> Unencrypted Data: '.$output;
$result = ['seal' => $sealed_data, 'envelope' => $envelope];
return json_encode($result);
} catch (Exception $ex) {
dd($ex);
throw new Exception($ex->getMessage());
}
}
public static function decryptByFaveoPrivateKey($encrypted) {
try {
$encrypted = json_decode($encrypted);
$sealed_data = $encrypted->seal;
$envelope = $encrypted->envelope;
$input = base64_decode($sealed_data);
$einput = base64_decode($envelope);
$path = storage_path('app' . DIRECTORY_SEPARATOR . 'private.key');
$key_content = file_get_contents($path);
$private_key = openssl_get_privatekey($key_content);
$plaintext = NULL;
openssl_open($input, $plaintext, $einput, $private_key);
return $plaintext;
} catch (Exception $ex) {
// dd($ex);
}
}
public static function _isCurl() {
return function_exists('curl_version');
}
}