Update v1.0.6.6

This commit is contained in:
sujitprasad
2016-03-11 18:36:32 +05:30
parent a77b7bf3e7
commit d54019198f
51 changed files with 4234 additions and 2401 deletions

View File

@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin\helpdesk;
// controller
use App\Http\Controllers\Common\PhpMailController;
use App\Http\Controllers\Common\SettingsController;
use App\Http\Controllers\Controller;
// request
use App\Http\Requests\helpdesk\AgentRequest;
@@ -14,20 +13,16 @@ use App\Model\helpdesk\Agent\Assign_team_agent;
use App\Model\helpdesk\Agent\Department;
use App\Model\helpdesk\Agent\Groups;
use App\Model\helpdesk\Agent\Teams;
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Settings\Company;
use App\Model\helpdesk\Settings\Email;
use App\Model\helpdesk\Utility\Timezones;
use App\User;
// classes
use DB;
use Exception;
use Hash;
use Mail;
/**
* AgentController
* This controller is used to CRUD category.
* This controller is used to CRUD Agents.
*
* @author Ladybird <info@ladybirdweb.com>
*/
@@ -44,8 +39,8 @@ class AgentController extends Controller
*/
public function __construct(PhpMailController $PhpMailController)
{
// creating an instance for the PhpmailController
$this->PhpMailController = $PhpMailController;
SettingsController::smtp();
// checking authentication
$this->middleware('auth');
// checking admin roles
@@ -55,84 +50,89 @@ class AgentController extends Controller
/**
* Get all agent list page.
*
* @param type User $user
*
* @return type Response
* @return type view
*/
public function index()
{
try {
return view('themes.default1.admin.helpdesk.agent.agents.index');
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* creating a new agent.
*
* @param type Assign_team_agent $team_assign_agent
* @param type Timezones $timezone
* @param type Groups $group
* @param type Department $department
* @param type Teams $team
* @param Assign_team_agent $team_assign_agent
* @param Timezones $timezone
* @param Groups $group
* @param Department $department
* @param Teams $team_all
*
* @return type view
*/
public function create(Assign_team_agent $team_assign_agent, Timezones $timezone, Groups $group, Department $department, Teams $team)
public function create(Timezones $timezone, Groups $group, Department $department, Teams $team_all)
{
try {
$team = $team->get();
// gte all the teams
$team = $team_all->get();
// get all the timezones
$timezones = $timezone->get();
// get all the groups
$groups = $group->get();
// get all department
$departments = $department->get();
// list all the teams in a single variable
$teams = $team->lists('id', 'name');
// returns to the page with all the variables and their datas
return view('themes.default1.admin.helpdesk.agent.agents.create', compact('assign', 'teams', 'agents', 'timezones', 'groups', 'departments', 'team'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->errorInfo[2]);
// returns if try fails with exception meaagse
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* store a new agent.
*
* @param type User $user
* @param type AgentRequest $request
* @param type Assign_team_agent $team_assign_agent
* @param User $user
* @param AgentRequest $request
* @param Assign_team_agent $team_assign_agent
*
* @return type Response
*/
public function store(User $user, AgentRequest $request, Assign_team_agent $team_assign_agent)
public function store(User $user, AgentRequest $request)
{
// dd($this->system_mail());
/* Insert to user table */
$user->role = 'agent';
// fixing the user role to agent
$user->fill($request->input())->save();
$password = $this->generateRandomString();
$user->password = Hash::make($password);
// generate password and has immediately to store
$user->password = Hash::make($this->generateRandomString());
// fetching all the team details checked for this user
$requests = $request->input('team_id');
// get user id of the inserted user detail
$id = $user->id;
// insert team
foreach ($requests as $req) {
// DB::insert('insert into team_assign_agent (team_id, agent_id) values (?,?)', [$req, $id]);
// insert all the selected team id to the team and agent relationship table
DB::insert('insert into team_assign_agent (team_id, agent_id) values (?,?)', [$req, $id]);
}
/* Succes And Failure condition */
// save user credentails
if ($user->save() == true) {
// fetch user credentails to send mail
$name = $user->user_name;
$email = $user->email;
$system_from = $this->company();
try {
// send mail on registration
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
} catch (Exception $e) {
// returns if try fails
return redirect('agents')->with('fails', 'Some error occured while sending mail to the agent. Please check email settings and try again');
}
// returns for the success case
return redirect('agents')->with('success', 'Agent Created sucessfully');
} else {
// returns if fails
return redirect('agents')->with('fails', 'Agent can not Create');
}
}
@@ -209,9 +209,11 @@ class AgentController extends Controller
/**
* Remove the specified agent from storage.
*
* @param type int $id
* @param type User $user
* @param type Assign_team_agent $team_assign_agent
* @param type $id
* @param User $user
* @param Assign_team_agent $team_assign_agent
*
* @throws Exception
*
* @return type Response
*/
@@ -230,8 +232,6 @@ class AgentController extends Controller
return redirect('agents')->with('success', 'Agent Deleted sucessfully');
} catch (\Exception $e) {
dd($e->errorInfo);
return redirect('agents')->with('fails', $error);
}
}
@@ -241,47 +241,21 @@ class AgentController extends Controller
*
* @param type $length
*
* @return type string
* @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;
}
/**
* Fetching comapny name to send mail.
*
* @return type
*/
public function company()
{
$company = Company::Where('id', '=', '1')->first();
if ($company->company_name == null) {
$company = 'Support Center';
} else {
$company = $company->company_name;
}
return $company;
}
/*
* System default email
*/
// public function system_mail() {
// $emails = Emails::all();
// $count_emails = $emails->count();
// if($count_emails > 1) {
// dd($emails);
// }
// $email = Email::where('id', '=', '1')->first();
// return $email->sys_email;
// }
}

View File

@@ -39,11 +39,9 @@ class BanlistController extends Controller
}
/**
* Display a listing of the resource.
* Display a listing of all the banned users.
*
* @param type Banlist $ban
*
* @return type Response
* @return type
*/
public function index()
{
@@ -57,7 +55,7 @@ class BanlistController extends Controller
}
/**
* Show the form for creating a new resource.
* Show the form for creating a banned user.
*
* @return type Response
*/
@@ -71,11 +69,10 @@ class BanlistController extends Controller
}
/**
* Store a newly created resource in storage.
* Store a new banned user credentials.
*
* @param type banlist $ban
* @param type BanRequest $request
* @param type User $user
* @param BanRequest $request
* @param User $user
*
* @return type Response
*/
@@ -107,22 +104,10 @@ class BanlistController extends Controller
}
/**
* Display the specified resource.
* Editing the details of the banned users.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param type int $id
* @param type Banlist $ban
* @param type $id
* @param User $ban
*
* @return type Response
*/
@@ -138,11 +123,11 @@ class BanlistController extends Controller
}
/**
* Update the specified resource in storage.
* Update the banned users.
*
* @param type int $id
* @param type Banlist $ban
* @param type BanlistRequest $request
* @param type $id
* @param User $ban
* @param BanlistRequest $request
*
* @return type Response
*/
@@ -152,7 +137,6 @@ class BanlistController extends Controller
$bans = $ban->whereId($id)->first();
$bans->internal_note = $request->input('internal_note');
$bans->ban = $request->input('ban');
// dd($request->input('ban'));
if ($bans->save()) {
return redirect('banlist')->with('success', 'Banned Email Updated sucessfully');
} else {
@@ -162,22 +146,4 @@ class BanlistController extends Controller
return redirect('banlist')->with('fails', 'Banned Email not Updated');
}
}
/*
* Remove the specified resource from storage.
* @param type int $id
* @param type Banlist $ban
* @return type Response
*/
// public function destroy($id, Banlist $ban) {
// $bans = $ban->whereId($id)->first();
// dd($bans);
// /* Success and Falure condition */
// try{
// $bans->delete();
// return redirect('banlist')->with('success', 'Banned Email Deleted sucessfully');
// } catch (Exception $e) {
// return redirect('banlist')->with('fails', 'Banned Email can not Delete'.'<li>'.$e->errorInfo[2].'</li>');
// }
// }
}

View File

@@ -7,26 +7,32 @@ use App\Http\Controllers\Controller;
// request
use App\Http\Requests\helpdesk\EmailsEditRequest;
use App\Http\Requests\helpdesk\EmailsRequest;
// model
use App\Model\helpdesk\Agent\Department;
// model
use App\Model\helpdesk\Email\Emails;
use App\Model\helpdesk\Manage\Help_topic;
use App\Model\helpdesk\Settings\Email;
use App\Model\helpdesk\Ticket\Ticket_Priority;
use App\Model\helpdesk\Utility\MailboxProtocol;
// classes
use Crypt;
// classes
use Exception;
use Illuminate\Http\Request;
//use PhpImap\Mailbox as ImapMailbox;
/**
* ======================================
* EmailsController.
* ======================================
* This Controller is used to define below mentioned set of functions applied to the Emails in the system.
*
* @author Ladybird <info@ladybirdweb.com>
* @author Ladybird <info@ladybirdweb.com>
*/
class EmailsController extends Controller
{
/**
* Create a new controller instance.
* Defining constructor variables.
*
* @return type
*/
@@ -37,20 +43,21 @@ class EmailsController extends Controller
}
/**
* Display a listing of the resource.
* Display a listing of the Emails.
*
* @param type Emails $emails
*
* @return type Response
* @return type view
*/
public function index(Emails $emails)
public function index(Emails $email)
{
try {
$emails = $emails->get();
// fetch all the emails from emails table
$emails = $email->get();
return view('themes.default1.admin.helpdesk.emails.emails.index', compact('emails'));
} catch (Exception $e) {
return view('404');
return redirect()->back()->with('fails', $e->getMessage());
}
}
@@ -64,81 +71,155 @@ class EmailsController extends Controller
*
* @return type Response
*/
public function create(Department $department, Help_topic $help, Ticket_Priority $priority, MailboxProtocol $mailbox_protocol)
public function create(Department $department, Help_topic $help, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol)
{
try {
// fetch all the departments from the department table
$departments = $department->get();
// fetch all the helptopics from the helptopic table
$helps = $help->get();
$priority = $priority->get();
// fetch all the types of priority from the ticket_priority table
$priority = $ticket_priority->get();
// fetch all the types of mailbox protocols from the mailbox_protocols table
$mailbox_protocols = $mailbox_protocol->get();
// return with all the table data
return view('themes.default1.admin.helpdesk.emails.emails.create', compact('mailbox_protocols', 'priority', 'departments', 'helps'));
} catch (Exception $e) {
return view('404');
// return error messages if any
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* Check for email input validation.
*
* @param EmailsRequest $request
*
* @return int
*/
public function validatingEmailSettings(Request $request)
{
$validator = \Validator::make(
[
'email_address' => $request->email_address,
'email_name' => $request->email_name,
'password' => $request->password,
], [
'email_address' => 'required|email|unique:emails',
'email_name' => 'required',
'password' => 'required',
]
);
if ($validator->fails()) {
$jsons = $validator->messages();
$val = '';
foreach ($jsons->all() as $key => $value) {
$val .= $value;
}
$return_data = rtrim(str_replace('.', ',', $val), ',');
return $return_data;
}
if ($request->fetching_status == 'on') {
$imap_check = $this->getImapStream($request);
if ($imap_check == 0) {
return 'Incoming email connection failed';
}
$need_to_check_imap = 1;
} else {
$imap_check = 0;
$need_to_check_imap = 0;
}
if ($request->sending_status == 'on') {
$smtp_check = $this->getSmtp($request);
if ($smtp_check == 0) {
return 'Outgoing email connection failed';
}
$need_to_check_smtp = 1;
} else {
$smtp_check = 0;
$need_to_check_smtp = 0;
}
if ($need_to_check_imap == 1 && $need_to_check_smtp == 1) {
if ($imap_check != 0 && $smtp_check != 0) {
$this->store($request);
$return = 1;
}
} elseif ($need_to_check_imap == 1 && $need_to_check_smtp == 0) {
if ($imap_check != 0 && $smtp_check == 0) {
$this->store($request);
$return = 1;
}
} elseif ($need_to_check_imap == 0 && $need_to_check_smtp == 1) {
if ($imap_check == 0 && $smtp_check != 0) {
$this->store($request);
$return = 1;
}
} elseif ($need_to_check_imap == 0 && $need_to_check_smtp == 0) {
if ($imap_check == 0 && $smtp_check == 0) {
$this->store($request, null);
$return = 1;
}
}
return $return;
}
/**
* Store a newly created resource in storage.
*
* @param type Emails $email
* @param type EmailsRequest $request
*
* @return type Response
* @return type Redirect
*/
public function store(Emails $email, EmailsRequest $request)
public function store($request)
{
// dd($request);
$email = new Emails();
try {
$password = $request->input('password');
$encrypted = Crypt::encrypt($password);
$department = $request->input('department');
$priority = $request->input('priority');
$help_topic = $request->input('help_topic');
if ($email->fill($request->except('password', 'department', 'priority', 'help_topic'))->save() == true) {
if ($request->input('department')) {
$email->department = $request->input('department');
// getConnection($request->input('email_name'), $request->input('email_address'), $request->input('email_address'))
// saving all the fields to the database
if ($email->fill($request->except('password', 'department', 'priority', 'help_topic', 'fetching_status', 'sending_status'))->save() == true) {
if ($request->fetching_status == 'on') {
$email->fetching_status = 1;
} else {
$email->department = null;
$email->fetching_status = 0;
}
if ($request->input('priority')) {
$email->priority = $request->input('priority');
if ($request->sending_status == 'on') {
$email->sending_status = 1;
} else {
$email->priority = null;
$email->sending_status = 0;
}
if ($request->input('help_topic')) {
$email->help_topic = $request->input('help_topic');
} else {
$email->help_topic = null;
}
$email->password = $encrypted;
$email->save();
// fetching department value
$email->department = $this->departmentValue($request->input('department'));
// fetching priority value
$email->priority = $this->priorityValue($request->input('priority'));
// fetching helptopic value
$email->help_topic = $this->helpTopicValue($request->input('help_topic'));
// inserting the encrypted value of password
$email->password = Crypt::encrypt($request->input('password'));
$email->save(); // run save
// Creating a default system email as the first email is inserted to the system
$email_settings = Email::where('id', '=', '1')->first();
$email_settings->sys_email = $email->id;
$email_settings->save();
return redirect('emails')->with('success', 'Email Created sucessfully');
// returns success message for successful email creation
// return redirect('emails')->with('success', 'Email Created sucessfully');
return 1;
} else {
return redirect('emails')->with('fails', 'Email can not Create');
// returns fail message for unsuccessful save execution
// return redirect('emails')->with('fails', 'Email can not Create');
return 0;
}
} catch (Exception $e) {
return redirect('emails')->with('fails', 'Email can not Create');
// returns if try fails
// return redirect()->back()->with('fails', $e->getMessage());
return 0;
}
}
/**
* Display the specified resource.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
@@ -151,21 +232,104 @@ class EmailsController extends Controller
*
* @return type Response
*/
public function edit($id, Department $department, Help_topic $help, Emails $email, Ticket_Priority $priority, MailboxProtocol $mailbox_protocol)
public function edit($id, Department $department, Help_topic $help, Emails $email, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol)
{
try {
// fetch the selected emails
$emails = $email->whereId($id)->first();
// get all the departments
$departments = $department->get();
// get all the helptopic
$helps = $help->get();
$priority = $priority->get();
// get all the priority
$priority = $ticket_priority->get();
// get all the mailbox protocols
$mailbox_protocols = $mailbox_protocol->get();
// return if the execution is succeeded
return view('themes.default1.admin.helpdesk.emails.emails.edit', compact('mailbox_protocols', 'priority', 'departments', 'helps', 'emails'));
} catch (Exception $e) {
return view('404');
// return if try fails
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* Check for email input validation.
*
* @param EmailsRequest $request
*
* @return int
*/
public function validatingEmailSettingsUpdate($id, Request $request)
{
$validator = \Validator::make(
[
'email_address' => $request->email_address,
'email_name' => $request->email_name,
'password' => $request->password,
], [
'email_address' => 'email',
'email_name' => 'required',
'password' => 'required',
]
);
if ($validator->fails()) {
$jsons = $validator->messages();
$val = '';
foreach ($jsons->all() as $key => $value) {
$val .= $value;
}
$return_data = rtrim(str_replace('.', ',', $val), ',');
return $return_data;
}
// return $request;
if ($request->fetching_status == 'on') {
$imap_check = $this->getImapStream($request);
if ($imap_check == 0) {
return 'Incoming email connection failed';
}
$need_to_check_imap = 1;
} else {
$imap_check = 0;
$need_to_check_imap = 0;
}
if ($request->sending_status == 'on') {
$smtp_check = $this->getSmtp($request);
if ($smtp_check == 0) {
return 'Outgoing email connection failed';
}
$need_to_check_smtp = 1;
} else {
$smtp_check = 0;
$need_to_check_smtp = 0;
}
if ($need_to_check_imap == 1 && $need_to_check_smtp == 1) {
if ($imap_check != 0 && $smtp_check != 0) {
$this->update($id, $request);
$return = 1;
}
} elseif ($need_to_check_imap == 1 && $need_to_check_smtp == 0) {
if ($imap_check != 0 && $smtp_check == 0) {
$this->update($id, $request);
$return = 1;
}
} elseif ($need_to_check_imap == 0 && $need_to_check_smtp == 1) {
if ($imap_check == 0 && $smtp_check != 0) {
$this->update($id, $request);
$return = 1;
}
} elseif ($need_to_check_imap == 0 && $need_to_check_smtp == 0) {
if ($imap_check == 0 && $smtp_check == 0) {
$this->update($id, $request);
$return = 1;
}
}
return $return;
}
/**
* Update the specified resource in storage.
*
@@ -175,39 +339,40 @@ class EmailsController extends Controller
*
* @return type Response
*/
public function update($id, Emails $email, EmailsEditRequest $request)
public function update($id, $request)
{
$password = $request->input('password');
$encrypted = Crypt::encrypt($password);
//echo $encrypted;
//$value = Crypt::decrypt($encrypted);
//echo $value;
try {
$emails = $email->whereId($id)->first();
// $emails->password = $encrypted;
$emails->fill($request->except('password', 'department', 'priority', 'help_topic'))->save();
if ($request->input('department')) {
$emails->department = $request->input('department');
// fetch the selected emails
$emails = Emails::whereId($id)->first();
// insert all the requested parameters with except
$emails->fill($request->except('password', 'department', 'priority', 'help_topic', 'fetching_status', 'sending_status'))->save();
if ($request->fetching_status == 'on') {
$emails->fetching_status = 1;
} else {
$emails->department = null;
$emails->fetching_status = 0;
}
if ($request->input('priority')) {
$emails->priority = $request->input('priority');
if ($request->sending_status == 'on') {
$emails->sending_status = 1;
} else {
$emails->priority = null;
$emails->sending_status = 0;
}
if ($request->input('help_topic')) {
$emails->help_topic = $request->input('help_topic');
} else {
$emails->help_topic = null;
}
$emails->password = $encrypted;
// fetching department value
$emails->department = $this->departmentValue($request->input('department'));
// fetching priority value
$emails->priority = $this->priorityValue($request->input('priority'));
// fetching helptopic value
$emails->help_topic = $this->helpTopicValue($request->input('help_topic'));
// inserting the encrypted value of password
$emails->password = Crypt::encrypt($request->input('password'));
$emails->save();
return redirect('emails')->with('success', 'Email Updated sucessfully');
// returns success message for successful email update
$return = 1;
} catch (Exception $e) {
return redirect('emails')->with('fails', 'Email not updated');
// returns if try fails
$return = $e->getMessage();
}
return $return;
}
/**
@@ -216,25 +381,168 @@ class EmailsController extends Controller
* @param type int $id
* @param type Emails $email
*
* @return type Response
* @return type Redirect
*/
public function destroy($id, Emails $email)
{
// fetching the details on the basis of the $id passed to the function
$default_system_email = Email::where('id', '=', '1')->first();
if ($default_system_email->sys_email) {
// checking if the default system email is the passed email
if ($id == $default_system_email->sys_email) {
return redirect('emails')->with('fails', 'You cannot delete system default Email');
}
}
try {
// fetching the database instance of the current email
$emails = $email->whereId($id)->first();
// checking if deleting the email is success or if it's carrying any dependencies
if ($emails->delete() == true) {
return redirect('emails')->with('success', 'Email Deleted sucessfully');
} else {
return redirect('emails')->with('fails', 'Email can not Delete ');
}
} catch (Exception $e) {
return redirect('emails')->with('fails', 'Email can not Delete ');
// returns if the try fails
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* Create imap connection.
*
* @param type $request
*
* @return type int
*/
public function getImapStream($request)
{
$fetching_status = $request->input('fetching_status');
$username = $request->input('email_address');
$password = $request->input('password');
$protocol_id = $request->input('mailbox_protocol');
$fetching_protocol = '/'.$request->input('fetching_protocol');
$fetching_encryption = '/'.$request->input('fetching_encryption');
if ($fetching_encryption == 'none') {
$fetching_encryption = 'novalidate-cert';
}
$mailbox_protocol = $fetching_protocol.$fetching_encryption;
$host = $request->input('fetching_host');
$port = $request->input('fetching_port');
$mailbox = '{'.$host.':'.$port.$mailbox_protocol.'}INBOX';
try {
$imap_stream = imap_open($mailbox, $username, $password);
} catch (\Exception $ex) {
return $ex->getMessage();
}
$imap_stream = imap_open($mailbox, $username, $password);
if ($imap_stream) {
$return = 1;
} else {
$return = 0;
}
return $return;
}
/**
* Check connection.
*
* @param type $imap_stream
*
* @return type int
*/
public function checkImapStream($imap_stream)
{
$check_imap_stream = imap_check($imap_stream);
if ($check_imap_stream) {
$imap_stream = 1;
} else {
$imap_stream = 0;
}
return $imap_stream;
}
/**
* Get smtp connection.
*
* @param type $request
*
* @return int
*/
public function getSmtp($request)
{
$sending_status = $request->input('sending_status');
$mail = new \PHPMailer();
$mail->isSMTP();
$mail->Host = $request->input('sending_host');
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $request->input('email_address');
$mail->Password = $request->input('password');
$mail->SMTPSecure = $request->input('sending_encryption');
$mail->Port = $request->input('sending_port');
if ($mail->smtpConnect() == true) {
$mail->smtpClose();
$return = 1;
} else {
$return = 0;
}
return $return;
}
/**
* Checking if department value is null.
*
* @param type $dept
*
* @return type string or null
*/
public function departmentValue($dept)
{
if ($dept) {
$email_department = $dept;
} else {
$email_department = null;
}
return $email_department;
}
/**
* Checking if priority value is null.
*
* @param type $priority
*
* @return type string or null
*/
public function priorityValue($priority)
{
if ($priority) {
$email_priority = $priority;
} else {
$email_priority = null;
}
return $email_priority;
}
/**
* Checking if helptopic value is null.
*
* @param type $help_topic
*
* @return type string or null
*/
public function helpTopicValue($help_topic)
{
if ($help_topic) {
$email_help_topic = $help_topic;
} else {
$email_help_topic = null;
}
return $email_help_topic;
}
}

View File

@@ -24,15 +24,14 @@ use Mail;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class TemplateController extends Controller
{
class TemplateController extends Controller {
/**
* Create a new controller instance.
*
* @return type void
*/
public function __construct(PhpMailController $PhpMailController)
{
public function __construct(PhpMailController $PhpMailController) {
$this->PhpMailController = $PhpMailController;
SettingsController::smtp();
$this->middleware('auth');
@@ -46,8 +45,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function index(Template $template)
{
public function index(Template $template) {
try {
$templates = $template->get();
@@ -65,8 +63,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function create(Languages $language, Template $template)
{
public function create(Languages $language, Template $template) {
try {
$templates = $template->get();
$languages = $language->get();
@@ -85,8 +82,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function store(Template $template, TemplateRequest $request)
{
public function store(Template $template, TemplateRequest $request) {
try {
/* Check whether function success or not */
if ($template->fill($request->input())->save() == true) {
@@ -109,8 +105,7 @@ class TemplateController extends Controller
*
* @return Response
*/
public function show($id)
{
public function show($id) {
//
}
@@ -123,8 +118,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function listdirectories()
{
public function listdirectories() {
$path = '../resources/views/emails/';
$directories = scandir($path);
$directory = str_replace('/', '-', $path);
@@ -132,32 +126,29 @@ class TemplateController extends Controller
return view('themes.default1.admin.helpdesk.emails.template.listdirectories', compact('directories', 'directory'));
}
public function listtemplates($template, $path)
{
public function listtemplates($template, $path) {
$paths = str_replace('-', '/', $path);
$directory2 = $paths.$template;
$directory2 = $paths . $template;
$templates = scandir($directory2);
$directory = str_replace('/', '-', $directory2.'/');
$directory = str_replace('/', '-', $directory2 . '/');
return view('themes.default1.admin.helpdesk.emails.template.listtemplates', compact('templates', 'directory'));
}
public function readtemplate($template, $path)
{
public function readtemplate($template, $path) {
$directory = str_replace('-', '/', $path);
$handle = fopen($directory.$template, 'r');
$contents = fread($handle, filesize($directory.$template));
$handle = fopen($directory . $template, 'r');
$contents = fread($handle, filesize($directory . $template));
fclose($handle);
return view('themes.default1.admin.helpdesk.emails.template.readtemplates', compact('contents', 'template', 'path'));
}
public function createtemplate()
{
public function createtemplate() {
$directory = '../resources/views/emails/';
$fname = Input::get('folder_name');
$filename = $directory.$fname;
$filename = $directory . $fname;
// images folder creation using php
// $mydir = dirname( __FILE__ )."/html/images";
@@ -169,7 +160,7 @@ class TemplateController extends Controller
if (!file_exists($filename)) {
mkdir($filename, 0777);
}
$files = array_filter(scandir($directory.'default'));
$files = array_filter(scandir($directory . 'default'));
foreach ($files as $file) {
if ($file === '.' or $file === '..') {
@@ -177,29 +168,27 @@ class TemplateController extends Controller
}
if (!is_dir($file)) {
// $file_to_go = str_replace("code/resources/views/emails/",'code/resources/views/emails/'.$fname,$file);
$destination = $directory.$fname.'/';
$destination = $directory . $fname . '/';
copy($directory.'default/'.$file, $destination.$file);
copy($directory . 'default/' . $file, $destination . $file);
}
}
return \Redirect::back()->with('success', 'Successfully copied');
}
public function writetemplate($template, $path)
{
public function writetemplate($template, $path) {
$directory = str_replace('-', '/', $path);
$b = Input::get('templatedata');
file_put_contents($directory.$template, print_r($b, true));
file_put_contents($directory . $template, print_r($b, true));
return \Redirect::back()->with('success', 'Successfully updated');
}
public function deletetemplate($template, $path)
{
public function deletetemplate($template, $path) {
$directory = str_replace('-', '/', $path);
$dir = $directory.$template;
$dir = $directory . $template;
$status = \DB::table('settings_email')->first();
if ($template == 'default' or $template == $status->template) {
return \Redirect::back()->with('fails', 'You cannot delete a default or active directory!');
@@ -208,7 +197,7 @@ class TemplateController extends Controller
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != '.' && $object != '..') {
unlink($dir.'/'.$object);
unlink($dir . '/' . $object);
}
}
rmdir($dir);
@@ -219,15 +208,13 @@ class TemplateController extends Controller
return \Redirect::back()->with('success', 'Successfully Deleted');
}
public function activateset($setname)
{
public function activateset($setname) {
\DB::table('settings_email')->update(['template' => $setname]);
return \Redirect::back()->with('success', 'You have Successfully Activated this Set');
}
public function edit($id, Template $template, Languages $language)
{
public function edit($id, Template $template, Languages $language) {
try {
$templates = $template->whereId($id)->first();
$languages = $language->get();
@@ -247,8 +234,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function update($id, Template $template, TemplateUdate $request)
{
public function update($id, Template $template, TemplateUdate $request) {
try {
//TODO validation
$templates = $template->whereId($id)->first();
@@ -274,8 +260,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function destroy($id, Template $template)
{
public function destroy($id, Template $template) {
try {
$templates = $template->whereId($id)->first();
/* Check whether function success or not */
@@ -299,8 +284,7 @@ class TemplateController extends Controller
*
* @return type Response
*/
public function formDiagno(Emails $email)
{
public function formDiagno(Emails $email) {
try {
$emails = $email->get();
@@ -317,15 +301,21 @@ class TemplateController extends Controller
*
* @return type
*/
public function postDiagno(Request $request)
{
public function postDiagno(Request $request) {
$email = $request->input('to');
if ($email == null) {
return redirect('getdiagno')->with('fails', 'Please provide E-mail address !');
}
// sending mail via php mailer
$mail = $this->PhpMailController->sendmail($from = 1, $to = ['email' => $email], $message = ['subject' => 'Checking the connection', 'scenario' => 'error-report', 'content' => 'Email Received Successfully'], $template_variables = ['system_error' => 'hello']);
$mail = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['email' => $email], $message = ['subject' => 'Checking the connection', 'scenario' => 'error-report', 'content' => 'Email Received Successfully'], $template_variables = ['system_error' => 'hello']);
return redirect('getdiagno')->with('success', 'Please check your mail. An E-mail has been sent to your E-mail address');
if($mail == null){
return redirect('getdiagno')->with('fails', 'Please check your E-mail settings. Unable to send mails');
} else {
return redirect('getdiagno')->with('success', 'Please check your mail. An E-mail has been sent to your E-mail address');
}
}
}

View File

@@ -51,137 +51,142 @@ class MailController extends Controller
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) {
$priority = $e_mail->priority;
$dept = $e_mail->department;
$helptopic = $e_mail->help_topic;
if ($priority == null) {
$priority = $ticket->first()->priority;
}
if ($dept == null) {
$dept = $system->first()->department;
}
if ($helptopic == null) {
$helptopic = $ticket->first()->help_topic;
}
// dd($dept);
$get_helptopic = Help_topic::where('id', '=', $helptopic)->first();
$sla = $get_helptopic->sla_plan;
// $dept = $e_mail->department;
$host = $e_mail->fetching_host;
$port = $e_mail->fetching_port;
$protocol = $e_mail->mailbox_protocol;
$get_mailboxprotocol = MailboxProtocol::where('id', '=', $protocol)->first();
$protocol = $get_mailboxprotocol->value;
$imap_config = '{'.$host.':'.$port.$protocol.'}INBOX';
$password = Crypt::decrypt($e_mail->password);
$mailbox = new ImapMailbox($imap_config, $e_mail->email_address, $password, __DIR__);
$mails = [];
$mailsIds = $mailbox->searchMailBox('SINCE '.date('d-M-Y', strtotime('-1 day')));
if (!$mailsIds) {
die('Mailbox is empty');
}
foreach ($mailsIds as $mailId) {
$overview = $mailbox->get_overview($mailId);
$var = $overview[0]->seen ? 'read' : 'unread';
if ($var == 'unread') {
$mail = $mailbox->getMail($mailId);
if ($settings_email->first()->email_collaborator == 1) {
$collaborator = $mail->cc;
if ($e_mail->fetching_status == 1) {
$priority = $e_mail->priority;
$dept = $e_mail->department;
$helptopic = $e_mail->help_topic;
if ($priority == null) {
$priority = $ticket->first()->priority;
}
if ($dept == null) {
$dept = $system->first()->department;
}
if ($helptopic == null) {
$helptopic = $ticket->first()->help_topic;
}
$get_helptopic = Help_topic::where('id', '=', $helptopic)->first();
$sla = $get_helptopic->sla_plan;
$host = $e_mail->fetching_host;
$port = $e_mail->fetching_port;
if ($e_mail->mailbox_protocol) {
$protocol_value = $e_mail->mailbox_protocol;
$get_mailboxprotocol = MailboxProtocol::where('id', '=', $protocol_value)->first();
$protocol = $get_mailboxprotocol->value;
} else {
if ($e_mail->fetching_protocol) {
$fetching_protocol = '/'.$e_mail->fetching_protocol;
} else {
$collaborator = null;
$fetching_protocol = '';
}
$body = $mail->textHtml;
if ($body == null) {
$body = $mailbox->backup_getmail($mailId);
$body = str_replace('\r\n', '<br/>', $body);
// var_dump($body);
}
$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('Y-m-d H:i:s', strtotime($date));
// dd($date);
if (isset($mail->subject)) {
$subject = $mail->subject;
if ($e_mail->fetching_encryption) {
$fetching_encryption = '/'.$e_mail->fetching_encryption;
} else {
$subject = 'No Subject';
$fetching_encryption = '';
}
$protocol = $fetching_protocol.$fetching_encryption;
}
$imap_config = '{'.$host.':'.$port.$protocol.'}INBOX';
$password = Crypt::decrypt($e_mail->password);
$mailbox = new ImapMailbox($imap_config, $e_mail->email_address, $password, __DIR__);
$mails = [];
$mailsIds = $mailbox->searchMailBox('SINCE '.date('d-M-Y', strtotime('-1 day')));
if (!$mailsIds) {
die('Mailbox is empty');
}
foreach ($mailsIds as $mailId) {
$overview = $mailbox->get_overview($mailId);
$var = $overview[0]->seen ? 'read' : 'unread';
if ($var == 'unread') {
$mail = $mailbox->getMail($mailId);
if ($settings_email->first()->email_collaborator == 1) {
$collaborator = $mail->cc;
} else {
$collaborator = null;
}
$body = $mail->textHtml;
if ($body == null) {
$body = $mailbox->backup_getmail($mailId);
$body = str_replace('\r\n', '<br/>', $body);
}
$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('Y-m-d H:i:s', strtotime($date));
if (isset($mail->subject)) {
$subject = $mail->subject;
} else {
$subject = 'No Subject';
}
$fromname = $mail->fromName;
$fromaddress = $mail->fromAddress;
$ticket_source = Ticket_source::where('name', '=', 'email')->first();
$source = $ticket_source->id;
$phone = '';
// dd($subject);
$fromname = $mail->fromName;
$fromaddress = $mail->fromAddress;
$ticket_source = Ticket_source::where('name', '=', 'email')->first();
$source = $ticket_source->id;
$phone = '';
$assign = $get_helptopic->auto_assign;
$form_data = null;
$result = $this->TicketController->create_user($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $form_data);
// 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;
$assign = $get_helptopic->auto_assign;
$form_data = null;
$result = $this->TicketController->create_user($fromaddress, $fromname, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $form_data);
// 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]);
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) {
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);
$thread = Ticket_Thread::where('id', '=', $thread_id)->first();
$thread->body = $this->separate_reply($body);
$thread->save();
}
$body = Encoding::fixUTF8($body);
$thread = Ticket_Thread::where('id', '=', $thread_id)->first();
$thread->body = $this->separate_reply($body);
$thread->save();
}
}
}

View File

@@ -81,7 +81,7 @@ class TicketController extends Controller
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -102,11 +102,10 @@ class TicketController extends Controller
} else {
$collabString = null;
}
// dd($ticket->id);
$threads = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first(); //
$count = Ticket_Thread::where('ticket_id', '=', $ticket->id)->count(); //Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
// $count = count($threads);
// dd($threads);
$attachment = Ticket_attachments::where('thread_id', '=', $threads->id)->get();
$attachCount = count($attachment);
if ($attachCount > 0) {
@@ -114,7 +113,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -125,7 +123,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -182,20 +179,15 @@ class TicketController extends Controller
public function get_open()
{
if (Auth::user()->role == 'admin') {
// $tickets = Tickets::where('status','=',1)->get();;
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('assigned_to', '=', 0)->get();
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->get();
} else {
// $dept = DB::table('department')->where('name','=',Auth::user()->primary_dpt)->first();
// $tickets = Tickets::where('status',1)->where('dept_id', '=', $dept->id)->get();
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('assigned_to', '=', 0)->where('dept_id', '=', $dept->id)->get();
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('dept_id', '=', $dept->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -225,7 +217,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -236,7 +227,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -244,7 +234,7 @@ class TicketController extends Controller
return "<span style='color:#508983'>".$from->user_name.'</span>';
})
->addColumn('Last Replier', function ($ticket) {
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '=', 0)->max('id');
$TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
$LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
if ($LastResponse->role == 'user') {
@@ -273,7 +263,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -294,20 +283,15 @@ class TicketController extends Controller
public function get_answered()
{
if (Auth::user()->role == 'admin') {
// $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 1)->get();
} else {
// $dept = Department::where('name','=',Auth::user()->primary_dpt)->first();
// $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('status', '=', 1)->where('isanswered', '=', 1)->where('dept_id', '=', $dept->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -337,7 +321,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -348,7 +331,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -385,7 +367,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -414,7 +395,7 @@ class TicketController extends Controller
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -444,7 +425,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -455,7 +435,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -492,7 +471,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -531,7 +509,7 @@ class TicketController extends Controller
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -561,7 +539,7 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
->addColumn('ticket_number', function ($ticket) {
@@ -571,7 +549,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -608,7 +585,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -637,7 +613,7 @@ class TicketController extends Controller
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -667,7 +643,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -678,7 +653,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -715,7 +689,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -768,8 +741,6 @@ class TicketController extends Controller
return Redirect('newticket')->with('fails', 'fails');
}
} catch (Exception $e) {
// dd($e);
return Redirect()->back()->with('fails', '<li>'.$e->errorInfo.'</li>');
}
}
@@ -783,21 +754,6 @@ class TicketController extends Controller
*/
public function thread($id)
{
/* $lock = Tickets::where('id','=',$id)->first();
if($lock->lock_by == Auth::user()->id || $lock->lock_at < date('Y-m-d H:i:s', strtotime('-3 minutes', strtotime($lock->lock_at)))) {
if(Auth::user()->role == 'agent'){
$dept = Department::where('id','=',Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('id', '=', $id)->where('dept_id','=', $dept->id)->first();
} else {
$tickets = Tickets::where('id', '=', $id)->first();
}
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
return view('themes.default1.agent.helpdesk.ticket.timeline', compact('tickets'), compact('thread'));
} else {
return Redirect()->back()->with('fails', 'This ticket has been locked by other agent');
} */
if (Auth::user()->role == 'agent') {
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
@@ -807,11 +763,11 @@ class TicketController extends Controller
} elseif (Auth::user()->role == 'user') {
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
$ticket_id = \Crypt::encrypt($id);
// dd($ticket_id);
return redirect()->route('check_ticket', compact('ticket_id'));
}
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
//$tickets = Tickets::where('id', '=', $id)->first();
return view('themes.default1.agent.helpdesk.ticket.timeline', compact('tickets'), compact('thread'));
}
@@ -834,16 +790,14 @@ class TicketController extends Controller
$source = $eventthread->source;
$form_data = $request->except('reply_content', 'ticket_ID', 'attachment');
\Event::fire(new \App\Events\ClientTicketFormPost($form_data, $emailadd, $source));
// dd($attachments);
// }
//return $attachments;
$reply_content = $request->input('reply_content');
$thread->ticket_id = $request->input('ticket_ID');
$thread->poster = 'support';
$thread->body = $request->input('reply_content');
$thread->user_id = Auth::user()->id;
$ticket_id = $request->input('ticket_ID');
//dd($ticket_id);
$tickets = Tickets::where('id', '=', $ticket_id)->first();
$tickets->isanswered = '1';
$tickets->save();
@@ -871,19 +825,13 @@ class TicketController extends Controller
}
$thread->save();
//$atachPath = '';
foreach ($attachments as $attachment) {
if ($attachment != null) {
$name = $attachment->getClientOriginalName();
//dd(dirname($attachment));
$type = $attachment->getClientOriginalExtension();
$size = $attachment->getSize();
$data = file_get_contents($attachment->getRealPath());
// $tem_path = $attachment->getRealPath();
// $tem = basename($tem_path).PHP_EOL;
// //dd($tem);
$attachPath = $attachment->getRealPath();
//dd($attachPath);
$ta->create(['thread_id' => $thread->id, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $data, 'poster' => 'ATTACHMENT']);
$check_attachment = 1;
@@ -914,7 +862,6 @@ class TicketController extends Controller
$message = '';
if ($check_attachment == 1) {
$attachment_files = $attachments;
// dd($attachment_files);
} else {
$attachment_files = null;
}
@@ -1054,8 +1001,6 @@ class TicketController extends Controller
public function create_user($emailadd, $username, $subject, $body, $phone, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $from_data)
{
// define global variables
// dd($source);
// dd($emailadd);
$email;
$username;
@@ -1083,17 +1028,10 @@ class TicketController extends Controller
$user_id = $user->id;
// Event fire
\Event::fire(new \App\Events\ReadMailEvent($user_id, $password));
// if (Mail::send('emails.pass', ['password' => $password, 'name' => $username, 'from'=>$company,'emailadd' => $emailadd], function ($message) use ($emailadd, $username,$company) {
// $message->to($emailadd, $username)->subject('Welcome to '.$company.' helpdesk');
// })) {
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $username, 'email' => $emailadd], $message = ['subject' => 'Welcome to '.$company.' helpdesk', 'scenario' => 'registration-notification'], $template_variables = ['user' => $username, 'email_address' => $emailadd, 'user_password' => $password]);
} catch (\Exception $e) {
// return 0;
}
// $message->to($emailadd, $username)->subject('Welcome to '.$company.' helpdesk');
// })) {
// need to do something here....
}
} else {
$username = $checkemail->username;
@@ -1103,14 +1041,6 @@ class TicketController extends Controller
$ticket_number2 = $ticket_number[0];
$ticketdata = Tickets::where('ticket_number', '=', $ticket_number2)->first();
$threaddata = Ticket_Thread::where('ticket_id', '=', $ticketdata->id)->first();
// $sending_emails = Emails::where('department', '=', $ticketdata->dept_id)->first();
// if($sending_emails == null) {
// $from_email = $this->system_mail();
// } else {
// $from_email = $sending_emails->id;
// }
// dd($threaddata);
$is_reply = $ticket_number[1];
$system = $this->system();
$updated_subject = $threaddata->title.'[#'.$ticket_number2.']';
@@ -1125,19 +1055,12 @@ class TicketController extends Controller
}
if ($source == 3) {
// Mail::send('emails.Ticket_Create', ['sign'=>$sign, 'content' => $body, 'name' => $username, 'ticket_number' => $ticket_number2, 'system' => $system], function ($message) use ($emailadd, $username, $ticket_number2, $updated_subject) {
// $message->to($emailadd, $username)->subject($updated_subject);
// });
// dd($body);
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['name' => $username, 'email' => $emailadd], $message = ['subject' => $updated_subject, 'scenario' => 'create-ticket-by-agent', 'body' => $body], $template_variables = ['agent_sign' => Auth::user()->agent_sign, 'ticket_number' => $ticket_number2]);
} catch (\Exception $e) {
}
} else {
$body2 = null;
// Mail::send('emails.Ticket_Create', ['sign'=>$sign, 'content' => $body2, 'name' => $username, 'ticket_number' => $ticket_number2, 'system' => $system], function ($message) use ($emailadd, $username, $ticket_number2, $updated_subject) {
// $message->to($emailadd, $username)->subject($updated_subject);
// });
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['name' => $username, 'email' => $emailadd], $message = ['subject' => $updated_subject, 'scenario' => 'create-ticket'], $template_variables = ['user' => $username, 'ticket_number' => $ticket_number2, 'department_sign' => '']);
} catch (\Exception $e) {
@@ -1149,13 +1072,9 @@ class TicketController extends Controller
if (Alert::first()->ticket_status == 1 || Alert::first()->ticket_admin_email == 1) {
// send email to admin
$admins = User::where('role', '=', 'admin')->get();
// $ticket_creator = $user->user_name;
foreach ($admins as $admin) {
$admin_email = $admin->email;
$admin_user = $admin->first_name;
// Mail::send('emails.'.$mail, ['agent' => $admin_user,'content'=>$body, 'ticket_number' => $ticket_number2, 'from'=>$company, 'email' => $emailadd, 'name' => $ticket_creator, 'system' => $system], function ($message) use ($admin_email, $admin_user, $ticket_number2, $updated_subject) {
// $message->to($admin_email, $admin_user)->subject($updated_subject);
// });
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $admin_user, 'email' => $admin_email], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $admin_user, 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $admin_user, 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]);
} catch (\Exception $e) {
@@ -1167,16 +1086,12 @@ class TicketController extends Controller
if (Alert::first()->ticket_status == 1 || Alert::first()->ticket_department_member == 1) {
// send email to agents
$agents = User::where('role', '=', 'agent')->get();
// dd($agents);
foreach ($agents as $agent) {
$department_data = Department::where('id', '=', $ticketdata->dept_id)->first();
if ($department_data->name == $agent->primary_dpt) {
$agent_email = $agent->email;
$agent_user = $agent->first_name;
// Mail::send('emails.'.$mail, ['agent' => $agent_user ,'content'=>$body , 'ticket_number' => $ticket_number2, 'from'=>$company, 'email' => $emailadd, 'name' => $ticket_creator, 'system' => $system], function ($message) use ($agent_email, $agent_user, $ticket_number2, $updated_subject) {
// $message->to($agent_email, $agent_user)->subject($updated_subject);
// });
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $agent_user, 'email' => $agent_email], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $admin_user, 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $agent_user, 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]);
} catch (\Exception $e) {
@@ -1190,9 +1105,6 @@ class TicketController extends Controller
$assigned_to = User::where('id', '=', $ticketdata->assigned_to)->first();
$agent_email = $assigned_to->email;
$agent_user = $assigned_to->first_name;
// Mail::send('emails.'.$mail, ['agent' => $assigned_to->user_name ,'content'=>$body , 'ticket_number' => $ticket_number2, 'from'=>$company, 'email' => $assigned_to->email, 'name' => $ticket_creator, 'system' => $system], function ($message) use ($agent_email, $agent_user, $ticket_number2, $updated_subject) {
// $message->to($agent_email, $agent_user)->subject($updated_subject);
// });
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $agent_user, 'email' => $agent_email], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $admin_user, 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $assigned_to->user_name, 'ticket_number' => $ticket_number2, 'email_address' => $assigned_to->email, 'name' => $ticket_creator]);
} catch (\Exception $e) {
@@ -1253,12 +1165,8 @@ class TicketController extends Controller
*/
public function check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data)
{
// $read_ticket_number = substr($subject, 0, 6);
$read_ticket_number = explode('[#', $subject);
if (isset($read_ticket_number[1])) {
// dd($read_ticket_number);
// if ($read_ticket_number == 'Re: [#' or $read_ticket_number == 'RE: [#') {
// dd($read_ticket_number);
$separate = explode(']', $read_ticket_number[1]);
$new_subject = substr($separate[0], 0, 20);
$find_number = Tickets::where('ticket_number', '=', $new_subject)->first();
@@ -1346,18 +1254,15 @@ class TicketController extends Controller
$sla_plan = Sla_plan::where('id', '=', $sla)->first();
$ovdate = $ticket->created_at;
// dd($sla_plan->grace_period);
$new_date = date_add($ovdate, date_interval_create_from_date_string($sla_plan->grace_period));
$ticket->duedate = $new_date;
$ticket->save();
// dd($ticket->duedate);
$ticket_number = $ticket->ticket_number;
$id = $ticket->id;
// store Form Data
// Form Data comes from raising a ticket from client panel
// dd($helptopic);
if ($form_data != null) {
$help_topic = Help_topic::where('id', '=', $helptopic)->first();
$forms = Fields::where('forms_id', '=', $help_topic->custom_form)->get();
@@ -1374,7 +1279,6 @@ class TicketController extends Controller
}
}
// store collaborators
// dd($headers);
$this->storeCollaborators($headers, $id);
if ($this->ticketThread($subject, $body, $id, $user_id) == true) {
return $ticket_number;
@@ -1456,10 +1360,6 @@ class TicketController extends Controller
$system_from = $this->company();
// Mail::send('emails.close_ticket', ['ticket_number' => $ticket_number, 'from'=>$company], function ($message) use ($email, $user_name, $ticket_number, $ticket_subject) {
// $message->to($email, $user_name)->subject($ticket_subject.'[#' . $ticket_number . ']');
// });
$sending_emails = Emails::where('department', '=', $ticket_status->dept_id)->first();
if ($sending_emails == null) {
$from_email = $this->system_mail();
@@ -1538,15 +1438,15 @@ class TicketController extends Controller
{
$ticket_delete = $ticket->where('id', '=', $id)->first();
if ($ticket_delete->status == 5) {
$ticket_delete->delete();
$ticket_threads = Ticket_Thread::where('ticket_id', '=', $id)->get();
foreach ($ticket_threads as $ticket_thread) {
$ticket_attachments = Ticket_attachments::where('thread_id', '=', $ticket_thread->id)->get();
foreach ($ticket_attachments as $ticket_attachment) {
$ticket_attachment->delete();
}
$ticket_thread->delete();
}
$ticket_attachments = Ticket_attachments::where('ticket_id', '=', $id)->get();
foreach ($ticket_attachments as $ticket_attachment) {
$ticket_attachment->delete();
}
$ticket_delete->delete();
return 'your ticket has been delete';
} else {
@@ -1615,14 +1515,6 @@ class TicketController extends Controller
$thread->is_internal = 1;
$thread->body = 'This Ticket has been assigned to '.$assignee;
$thread->save();
// $master = Auth::user()->first_name . " " . Auth::user()->last_name;
// if(Alert::first()->internal_status == 1 || Alert::first()->internal_assigned_agent == 1) {
// // ticket assigned send mail
// Mail::send('emails.Ticket_assign', ['agent' => $agent, 'ticket_number' => $ticket_number, 'from'=>$company, 'master' => $master, 'system' => $system], function ($message) use ($agent_email, $agent, $ticket_number, $ticket_subject) {
// $message->to($agent_email, $agent)->subject($ticket_subject.'[#' . $ticket_number . ']');
// });
// }
} elseif ($assign_to[0] == 'user') {
$ticket->assigned_to = $assign_to[1];
$user_detail = User::where('id', '=', $assign_to[1])->first();
@@ -1648,24 +1540,11 @@ class TicketController extends Controller
$agent_email = $user_detail->email;
$master = Auth::user()->first_name.' '.Auth::user()->last_name;
// if(Alert::first()->internal_status == 1 || Alert::first()->internal_assigned_agent == 1) {
// ticket assigned send mail
// Mail::send('emails.Ticket_assign', ['agent' => $agent, 'ticket_number' => $ticket_number, 'from'=>$company, 'master' => $master, 'system' => $system], function ($message) use ($agent_email, $agent, $ticket_number, $ticket_subject) {
// $message->to($agent_email, $agent)->subject($ticket_subject.'[#' . $ticket_number . ']');
// });
// $sending_emails = Emails::where('department', '=', $ticket->dept_id)->first();
// if($sending_emails == null) {
// $from_email = $this->system_mail();
// } else {
// $from_email = $sending_emails->id;
// }
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket->dept_id), $to = ['name' => $agent, 'email' => $agent_email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'assign-ticket'], $template_variables = ['ticket_agent_name' => $agent, 'ticket_number' => $ticket_number, 'ticket_assigner' => $master]);
} catch (\Exception $e) {
return 0;
}
// }
}
return 1;
@@ -1685,7 +1564,6 @@ class TicketController extends Controller
$NewThread = new Ticket_Thread();
$NewThread->ticket_id = $thread->ticket_id;
$NewThread->user_id = Auth::user()->id;
// $NewThread->thread_type = 'M';
$NewThread->is_internal = 1;
$NewThread->poster = Auth::user()->role;
$NewThread->title = $thread->title;
@@ -1705,9 +1583,6 @@ class TicketController extends Controller
public function surrender($id)
{
$ticket = Tickets::where('id', '=', $id)->first();
// if($ticket->assigned_to == Auth::user()->id)
// {
$InternalContent = Auth::user()->first_name.' '.Auth::user()->last_name.' has Surrendered the assigned Ticket';
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first();
$NewThread = new Ticket_Thread();
@@ -1718,7 +1593,6 @@ class TicketController extends Controller
$NewThread->title = $thread->title;
$NewThread->body = $InternalContent;
$NewThread->save();
// }
$ticket->assigned_to = null;
$ticket->save();
@@ -1791,16 +1665,6 @@ class TicketController extends Controller
$create_user->password = Hash::make($password);
$create_user->save();
$user_id = $create_user->id;
// Mail::send('emails.pass', ['password' => $password, 'name' => $name, 'from'=>$company,'emailadd' => $email], function ($message) use ($email, $name) {
// $message->to($email, $name)->subject('password');
// });
// $sending_emails = Emails::where('department', '=', $ticket_status->dept_id)->first();
// if($sending_emails == null) {
// $from_email = $this->system_mail();
// } else {
// $from_email = $sending_emails->id;
// }
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
} catch (\Exception $e) {
@@ -1855,36 +1719,6 @@ class TicketController extends Controller
return $system;
}
/**
* function to search.
*
* @return type
*/
// public function search() {
// $product = Input::get('type');
// $word = Input::get('name_startsWith');
// if ($product == 'product') {
// $starts_with = strtoupper($word);
// $rows = DB::table('users')->select('user_name')->where('name', 'LIKE', $starts_with . '%')->get();
// $data = array();
// foreach ($rows as $row) {
// array_push($data, $row->name);
// }
// print_r(json_encode($data));
// }
// if ($product == 'product_table') {
// $row_num = Input::get('row_num');
// $starts_with = strtoupper($word);
// $rows = DB::table('product')->select('name', 'description', 'cost_price')->where('name', 'LIKE', $starts_with . '%')->get();
// $data = array();
// foreach ($rows as $row) {
// $name = $row->name . '|' . $row->description . '|' . $row->cost_price . '|' . $row_num;
// array_push($data, $name);
// }
// print_r(json_encode($data));
// }
// }
/**
* shows trashed tickets.
*
@@ -1898,24 +1732,15 @@ class TicketController extends Controller
public function get_trash()
{
if (Auth::user()->role == 'admin') {
// $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
$tickets = Tickets::where('status', '=', 5)->get();
// $tickets = Tickets::where('assigned_to', '=', null)->where('status','1')->get();
} else {
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('status', '=', 5)->where('dept_id', '=', $dept->id)->get();
// $dept = Department::where('name','=',Auth::user()->primary_dpt)->first();
// $tickets = Tickets::where('assigned_to', '=', null)->where('dept_id','=',$dept->id)->get();
// $dept = Department::where('name','=',Auth::user()->primary_dpt)->first();
// $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -1945,7 +1770,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -1956,7 +1780,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -1993,7 +1816,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -2014,20 +1836,15 @@ class TicketController extends Controller
public function get_unassigned()
{
if (Auth::user()->role == 'admin') {
// $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
$tickets = Tickets::where('assigned_to', '=', null)->where('status', '1')->get();
} else {
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
$tickets = Tickets::where('assigned_to', '=', null)->where('dept_id', '=', $dept->id)->get();
// $dept = Department::where('name','=',Auth::user()->primary_dpt)->first();
// $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
}
return \Datatable::collection(new Collection($tickets))
->addColumn('id', function ($ticket) {
return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='".$ticket->id."'></input>";
return "<input type='checkbox' name='select_all[]' id='".$ticket->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$ticket->id."'></input>";
})
->addColumn('subject', function ($ticket) {
$subject = DB::table('ticket_thread')->select('title')->where('ticket_id', '=', $ticket->id)->first();
@@ -2057,7 +1874,6 @@ class TicketController extends Controller
} else {
$attachString = '';
}
//return $threads->id;
return "<a href='".route('ticket.thread', [$ticket->id])."' title='".$subject->title."'>".$string."&nbsp;<span style='color:green'>(".$count.")<i class='fa fa-comment'></i></span></a>".$collabString.$attachString;
})
@@ -2068,7 +1884,6 @@ class TicketController extends Controller
$priority = DB::table('ticket_priority')->select('priority_desc', 'priority_color')->where('priority_id', '=', $ticket->priority_id)->first();
return '<span class="btn btn-'.$priority->priority_color.' btn-xs">'.$priority->priority_desc.'</span>';
//return "loda";
})
->addColumn('from', function ($ticket) {
$from = DB::table('users')->select('user_name')->where('id', '=', $ticket->user_id)->first();
@@ -2105,7 +1920,6 @@ class TicketController extends Controller
$TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
$TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
// return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
return UTC::usertimezone($TicketDatarow->updated_at);
})
->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')
@@ -2222,16 +2036,6 @@ class TicketController extends Controller
if ($user->save()) {
$user_id = $user->id;
// Mail::send('emails.pass', ['password' => $password, 'name' => $name, 'from'=>$company,'emailadd'=>$email], function ($message) use ($email, $name) {
// $message->to($email, $name)->subject('password');
// });
// $sending_emails = Emails::where('department', '=', $ticket_status->dept_id)->first();
// if($sending_emails == null) {
// $from_email = $this->system_mail();
// } else {
// $from_email = $sending_emails->id;
// }
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
}
$ticket_collaborator = new Ticket_Collaborator();
@@ -2243,7 +2047,6 @@ class TicketController extends Controller
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$user->user_name.'</h4><div id="message-success1">'.$user->email.'</div></div>';
}
// return '<div id="alert11" class="alert alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'</div></div>';
}
/**
@@ -2285,6 +2088,7 @@ class TicketController extends Controller
$ticket->reopened_at = date('Y-m-d H:i:s');
$ticket->closed = 0;
$ticket->closed_at = null;
$ticket->save();
}
}
@@ -2490,9 +2294,9 @@ class TicketController extends Controller
$name = Input::get('name');
$returnValue = $this->changeOwnerAdd($email, $name, $ticket_id);
if ($returnValue === 0) {
return 4; //'<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">This user already Exists</div></div>';
return 4;
} elseif ($returnValue === 2) {
return 5; //'<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">Enter valid email address.</div></div>';
return 5;
} else {
//do nothing
}
@@ -2555,9 +2359,9 @@ class TicketController extends Controller
$user = User::where('email', '=', $email)->first();
$count = count($user);
if ($count === 1) {
return 0; //'<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">This user already Exists</div></div>';
return 0;
} elseif ($validator->fails()) {
return 2; //'<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">Enter valid email address. Exists</div></div>';
return 2;
} else {
$company = $this->company();
$user = new User();
@@ -2571,13 +2375,11 @@ class TicketController extends Controller
try {
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]);
} catch (\Exception $e) {
// dd($e);
}
}
return 1; // '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$user->user_name.'</h4><div id="message-success1">'.$user->email.'</div></div>';
return 1;
}
// return '<div id="alert11" class="alert alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'</div></div>';
}
public function getMergeTickets($id)
@@ -2693,7 +2495,6 @@ class TicketController extends Controller
"'>#".$parent_ticket->ticket_number.'</a><br>'.$reason;
$new_thread->format = $thread->format;
$new_thread->ip_address = $thread->ip_address;
//$new_thread->save();
$new_parent_thread = new Ticket_thread();
$new_parent_thread->ticket_id = $p_id;
@@ -2705,7 +2506,6 @@ class TicketController extends Controller
$new_parent_thread->body = Lang::get('lang.ticket')."&nbsp;<a href='".route('ticket.thread', [$value])."'>#".$ticket->ticket_number.'</a>&nbsp'.Lang::get('lang.ticket_merged').'<br>'.$reason;
$new_parent_thread->format = $parent_thread->format;
$new_parent_thread->ip_address = $parent_thread->ip_address;
//$new_parent_thread->save();
if ($new_thread->save() && $new_parent_thread->save()) {
$success = 1;
} else {

View File

@@ -38,7 +38,6 @@ class UserController extends Controller
* 1. authentication
* 2. user roles
* 3. roles must be agent.
*
* @return void
*/
public function __construct()
@@ -51,9 +50,7 @@ class UserController extends Controller
/**
* Display all list of the users.
*
* @param type User $user
*
* @return type view
*/
public function index()
@@ -68,15 +65,14 @@ class UserController extends Controller
/**
* 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 */
->searchColumns('user_name')
/* searchable column username and email*/
->searchColumns('user_name', 'email', 'phone')
/* order column username and email */
->orderColumns('user_name', 'email')
/* column username */
@@ -85,14 +81,14 @@ class UserController extends Controller
$username = substr($model->user_name, 0, 30);
$username = substr($username, 0, strrpos($username, ' ')).' ...';
} else {
$username = $model->user_name;
$username = "<a href='".route('user.edit', $model->id)."'>".$model->user_name."</a>";
}
return $username;
})
/* column email */
->addColumn('email', function ($model) {
$email = $model->email;
$email = "<a href='".route('user.edit', $model->id)."'>".$model->email."</a>";
return $email;
})
@@ -147,7 +143,6 @@ class UserController extends Controller
/**
* Show the form for creating a new users.
*
* @return type view
*/
public function create()
@@ -161,10 +156,8 @@ class UserController extends Controller
/**
* 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)
@@ -191,10 +184,8 @@ class UserController extends Controller
/**
* Display the specified users.
*
* @param type int $id
* @param type User $user
*
* @return type view
*/
public function show($id, User $user)
@@ -211,10 +202,8 @@ class UserController extends Controller
/**
* 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)
@@ -231,16 +220,13 @@ class UserController extends Controller
/**
* 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 */
@@ -257,7 +243,6 @@ class UserController extends Controller
/**
* get agent profile page.
*
* @return type view
*/
public function getProfile()
@@ -272,7 +257,6 @@ class UserController extends Controller
/**
* get profile edit page.
*
* @return type view
*/
public function getProfileedit()
@@ -287,10 +271,8 @@ class UserController extends Controller
/**
* post profile edit.
*
* @param type int $id
* @param type ProfileRequest $request
*
* @return type Redirect
*/
public function postProfileedit(ProfileRequest $request)
@@ -339,10 +321,8 @@ class UserController extends Controller
/**
* Post profile password.
*
* @param type int $id
* @param type ProfilePassword $request
*
* @return type Redirect
*/
public function postProfilePassword($id, ProfilePassword $request)
@@ -354,7 +334,6 @@ class UserController extends Controller
$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]);
@@ -366,9 +345,7 @@ class UserController extends Controller
/**
* Assigning an user to an organization.
*
* @param type $id
*
* @return type boolean
*/
public function UserAssignOrg($id)
@@ -378,15 +355,12 @@ class UserController extends Controller
$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)

View File

@@ -555,9 +555,10 @@ class ApiController extends Controller
$result[$key]['picture'] = $path;
}
$result = $this->createPagination($result, 10);
//dd($result);
//$result->toJson();
return $result->toJson();
} catch (Exception $e) {
} catch (\Exception $e) {
$error = $e->getMessage();
$line = $e->getLine();
$file = $e->getFile();

View File

@@ -0,0 +1,114 @@
<?php
namespace App\Http\Controllers\Api\v1;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ApiExceptAuthController extends Controller
{
public $api_controller;
public function __construct(Request $request)
{
$this->request = $request;
$this->middleware('api');
}
/**
* Check the url is valid or not.
*
* @return json
*/
public function checkUrl()
{
//dd($this->request);
try {
$v = \Validator::make($this->request->all(), [
'url' => 'required|url',
]);
if ($v->fails()) {
$error = $v->errors();
return response()->json(compact('error'));
}
$url = $this->request->input('url');
$url = $url.'/api/v1/helpdesk/check-url';
$result = $this->CallGetApi($url);
// dd($result);
return response()->json(compact('result'));
} catch (\Exception $ex) {
$error = $ex->getMessage();
return $error;
} catch (\Symfony\Component\HttpKernel\Exception\HttpException $ex) {
return ['status' => 'fails', 'code' => $ex->getStatusCode()];
}
}
/**
* Success for currect url.
*
* @return string
*/
public function urlResult()
{
try {
$result = ['status' => 'success'];
return $result;
} catch (\Symfony\Component\HttpKernel\Exception\HttpException $ex) {
return ['status' => 'fails', 'code' => $ex->getStatusCode()];
}
}
/**
* Call curl function for Get Method.
*
* @param type $url
*
* @return type int|string|json
*/
public function callGetApi($url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if (curl_errno($curl)) {
//echo 'error:' . curl_error($curl);
}
return $response;
curl_close($curl);
}
/**
* Call curl function for POST Method.
*
* @param type $url
* @param type $data
*
* @return type int|string|json
*/
public function callPostApi($url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo 'error:'.curl_error($curl);
}
return $response;
curl_close($curl);
}
}

View File

@@ -473,6 +473,13 @@ class TestController extends Controller
public function getCustomersWith()
{
try {
//dd($this->server);
$url = $this->server.'helpdesk/customers-custom?api_key=9p41T2XFZ34YRZJUNQAdmM7iV0Rr1CjN&token='.\Config::get('app.token');
$_this = new self();
$respose = $_this->callGetApi($url);
dd($respose);
return $respose;
} catch (\Exception $e) {
$error = $e->getMessage();
$line = $e->getLine();

View File

@@ -64,6 +64,7 @@ class ClientTicketController extends Controller
$tickets->closed = 0;
$tickets->reopened_at = date('Y-m-d H:i:s');
$tickets->reopened = 1;
$tickets->isanswered = 0;
$threads = new Ticket_Thread();
$threads->user_id = Auth::user()->id;
$threads->ticket_id = $tickets->id;

View File

@@ -10,13 +10,16 @@ use App\Model\helpdesk\Settings\Email;
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 {
return $emails;
public function fetch_smtp_details($id) {
$emails = Emails::where('id', '=', $id)->first();
if ($emails->sending_status == 1) {
return $emails;
} else {
$emails = null;
return $emails;
}
}
/**
@@ -24,231 +27,235 @@ class PhpMailController extends Controller
*
* @return Mail
*/
public function sendmail($from, $to, $message, $template_variables)
{
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;
// 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;
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 = 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;
}
$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] . '\emails' . DIRECTORY_SEPARATOR . $status->template . DIRECTORY_SEPARATOR;
$directory = $path2[0].'\emails'.DIRECTORY_SEPARATOR.$status->template.DIRECTORY_SEPARATOR;
$handle = fopen($directory . $template . '.blade.php', 'r');
$contents = fread($handle, filesize($directory . $template . '.blade.php'));
fclose($handle);
$handle = fopen($directory.$template.'.blade.php', 'r');
$contents = fread($handle, filesize($directory.$template.'.blade.php'));
fclose($handle);
$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);
//$mail->SMTPDebug = 3; // Enable verbose debug output
$contents = $messagebody;
}
$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
// 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);
$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);
}
}
}
$mail->addBCC($bc);
$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);
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 = $subject;
if ($template == 'ticket-reply-agent') {
$line = '---Reply above this line--- <br/><br/>';
$mail->Body = $line.$messagebody;
} else {
$mail->Body = $messagebody;
}
$mail->Subject = $subject;
if ($template == 'ticket-reply-agent') {
$line = '---Reply above this line--- <br/><br/>';
$mail->Body = $line . $messagebody;
} else {
$mail->Body = $messagebody;
}
// $mail->AltBody = $altbody;
// $mail->AltBody = $altbody;
if (!$mail->send()) {
// echo 'Message could not be sent.';
// echo 'Mailer Error: '.$mail->ErrorInfo;
} else {
// echo 'Message has been sent';
if (!$mail->send()) {
return null;
// echo 'Message could not be sent.';
// echo 'Mailer Error: '.$mail->ErrorInfo;
} else {
return 1;
// echo 'Message has been sent';
}
}
}
@@ -257,8 +264,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';
@@ -320,8 +326,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;
@@ -334,4 +339,5 @@ class PhpMailController extends Controller
}
}
}
}

View File

@@ -203,23 +203,30 @@ class InstallController extends Controller
$port = Input::get('port');
// Setting environment values
$ENV['APP_ENV'] = 'local';
$ENV['APP_DEBUG'] = 'false';
$ENV['APP_KEY'] = 'SomeRandomString';
$ENV['DB_TYPE'] = $default;
$ENV['DB_HOST'] = $host;
$ENV['DB_PORT'] = $port;
$ENV['DB_DATABASE'] = $database;
$ENV['DB_USERNAME'] = $dbusername;
$ENV['DB_PASSWORD'] = $dbpassword;
$ENV['MAIL_DRIVER'] = 'smtp';
$ENV['MAIL_HOST'] = 'mailtrap.io';
$ENV['MAIL_PORT'] = '2525';
$ENV['MAIL_USERNAME'] = 'null';
$ENV['MAIL_PASSWORD'] = 'null';
$ENV['CACHE_DRIVER'] = 'file';
$ENV['SESSION_DRIVER'] = 'file';
$ENV['QUEUE_DRIVER'] = 'sync';
// $_ENV['DB_TYPE'] = $default;
// $_ENV['DB_HOST'] = $host;
// $_ENV['DB_PORT'] = $port;
// $_ENV['DB_DATABASE'] = $database;
// $_ENV['DB_USERNAME'] = $dbusername;
// $_ENV['DB_PASSWORD'] = $dbpassword;
$ENV['APP_ENV'] = 'local';
$ENV['APP_DEBUG'] = 'false';
$ENV['APP_KEY'] = 'SomeRandomString';
$ENV['DB_TYPE'] = $default;
$ENV['DB_HOST'] = $host;
$ENV['DB_PORT'] = $port;
$ENV['DB_DATABASE'] = $database;
$ENV['DB_USERNAME'] = $dbusername;
$ENV['DB_PASSWORD'] = $dbpassword;
$ENV['MAIL_DRIVER'] = 'smtp';
$ENV['MAIL_HOST'] = 'mailtrap.io';
$ENV['MAIL_PORT'] = '2525';
$ENV['MAIL_USERNAME'] = 'null';
$ENV['MAIL_PASSWORD'] = 'null';
$ENV['CACHE_DRIVER'] = 'file';
$ENV['SESSION_DRIVER'] = 'file';
$ENV['QUEUE_DRIVER'] = 'sync';
$config = '';
foreach ($ENV as $key => $val) {