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');
}
}
}