This commit is contained in:
Manish Verma
2016-12-13 18:18:25 +05:30
parent fc98add11c
commit 2d8e640e9b
2314 changed files with 97798 additions and 75664 deletions

View File

@@ -3,21 +3,21 @@
namespace App\Http\Controllers\Admin\helpdesk;
// controllers
use App\Http\Controllers\Admin\MailFetch as Fetch;
use App\Http\Controllers\Controller;
use App\Http\Requests\helpdesk\EmailsRequest;
// model
use App\Http\Requests\helpdesk\Mail\MailRequest;
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;
// classes
use App\Model\helpdesk\Utility\MailboxProtocol;
use Crypt;
// classes
use Exception;
use Lang;
use App\Http\Requests\helpdesk\Mail\MailRequest;
use App\Http\Controllers\Admin\MailFetch as Fetch;
/**
* ======================================
@@ -27,15 +27,14 @@ use Lang;
*
* @author Ladybird <info@ladybirdweb.com>
*/
class EmailsController extends Controller
{
class EmailsController extends Controller {
/**
* Defining constructor variables.
*
* @return type
*/
public function __construct()
{
public function __construct() {
$this->middleware('auth');
$this->middleware('roles');
}
@@ -47,8 +46,7 @@ class EmailsController extends Controller
*
* @return type view
*/
public function index(Emails $email)
{
public function index(Emails $email) {
try {
// fetch all the emails from emails table
$emails = $email->get();
@@ -69,14 +67,13 @@ class EmailsController extends Controller
*
* @return type Response
*/
public function create(Department $department, Help_topic $help, Ticket_Priority $ticket_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->where('status', '=', 1)->get();
// fetch all the types of active priority from the ticket_priority table
// fetch all the types of priority from the ticket_priority table
$priority = $ticket_priority->where('status', '=', 1)->get();
// fetch all the types of mailbox protocols from the mailbox_protocols table
$mailbox_protocols = $mailbox_protocol->get();
@@ -99,8 +96,7 @@ class EmailsController extends Controller
*
* @return int
*/
public function validatingEmailSettings(MailRequest $request, $id = '')
{
public function validatingEmailSettings(MailRequest $request, $id = "") {
//dd($request->all());
try {
$service_request = $request->except('sending_status', '_token', 'email_address', 'email_name', 'password', 'department', 'priority', 'help_topic', 'fetching_protocol', 'fetching_host', 'fetching_port', 'fetching_encryption', 'imap_authentication', 'sending_protocol', 'sending_host', 'sending_port', 'sending_encryption', 'smtp_authentication', 'internal_notes', '_wysihtml5_mode', 'code');
@@ -118,10 +114,8 @@ class EmailsController extends Controller
}
if ($send == 1 && $fetch == 1) {
$this->store($request, $service_request, $id);
return $this->jsonResponse('success', Lang::get('lang.success'));
}
return $this->validateEmailError($send, $fetch);
} catch (Exception $ex) {
$message = $ex->getMessage();
@@ -129,13 +123,11 @@ class EmailsController extends Controller
$message = imap_last_error();
}
loging('mail-config', $message);
return $this->jsonResponse('fails', $message);
}
}
public function validateEmailError($out, $in)
{
public function validateEmailError($out, $in) {
if ($out !== 1) {
return $this->jsonResponse('fails', Lang::get('lang.outgoing_email_connection_failed'));
}
@@ -144,15 +136,13 @@ class EmailsController extends Controller
}
}
public function jsonResponse($type, $message)
{
public function jsonResponse($type, $message) {
if ($type == 'fails') {
$result = ['fails' => $message];
}
if ($type == 'success') {
$result = ['success' => $message];
}
return response()->json(compact('result'));
}
@@ -164,10 +154,9 @@ class EmailsController extends Controller
*
* @return type Redirect
*/
public function store($request, $service_request = [], $id = '')
{
public function store($request, $service_request = [], $id = "") {
$email = new Emails();
if ($id !== '') {
if ($id !== "") {
$email = $email->find($id);
}
@@ -219,7 +208,7 @@ class EmailsController extends Controller
if ($request->input('fetching_status')) {
$this->fetch($email);
}
if ($id === '') {
if ($id === "") {
// 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;
@@ -233,12 +222,31 @@ class EmailsController extends Controller
if ($request->input('fetching_status')) {
$this->fetch($email);
}
return 1;
}
public function sendDiagnoEmail($request)
{
public function checkMail($request) {
$mailservice_id = $request->input('sending_protocol');
$driver = $this->getDriver($mailservice_id);
$username = $request->input('email_address');
$password = $request->input('password');
$name = $request->input('email_name');
$host = $request->input('sending_host');
$port = $request->input('sending_port');
$enc = $request->input('sending_encryption');
$service_request = $request->except('sending_status', '_token', 'email_address', 'email_name', 'password', 'department', 'priority', 'help_topic', 'fetching_protocol', 'fetching_host', 'fetching_port', 'fetching_encryption', 'imap_authentication', 'sending_protocol', 'sending_host', 'sending_port', 'sending_encryption', 'smtp_authentication', 'internal_notes', '_wysihtml5_mode');
$this->emailService($driver, $service_request);
$this->setMailConfig($driver, $username, $name, $password, $enc, $host, $port);
$transport = \Swift_SmtpTransport::newInstance($host, $port, $enc);
$transport->setUsername($username);
$transport->setPassword($password);
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->getTransport()->start();
return 1;
}
public function sendDiagnoEmail($request) {
$mailservice_id = $request->input('sending_protocol');
$driver = $this->getDriver($mailservice_id);
$username = $request->input('email_address');
@@ -252,45 +260,41 @@ class EmailsController extends Controller
$this->emailService($driver, $service_request);
$this->setMailConfig($driver, $username, $name, $password, $enc, $host, $port);
$controller = new \App\Http\Controllers\Common\PhpMailController();
$subject = 'test';
$data = 'test';
$subject = "test";
$data = "test";
//dd(\Config::get('mail'),\Config::get('services'));
$send = $controller->laravelMail($username, $name, $subject, $data, [], []);
return $send;
}
public function setMailConfig($driver, $username, $name, $password, $enc, $host, $port)
{
public function setMailConfig($driver, $username, $name, $password, $enc, $host, $port) {
$configs = [
'username' => $username,
'from' => ['address' => $username, 'name' => $name],
'password' => $password,
'username' => $username,
'from' => ['address' => $username, 'name' => $name,],
'password' => $password,
'encryption' => $enc,
'host' => $host,
'port' => $port,
'driver' => $driver,
'host' => $host,
'port' => $port,
'driver' => $driver,
];
foreach ($configs as $key => $config) {
if (is_array($config)) {
foreach ($config as $from) {
\Config::set('mail.'.$key, $config);
\Config::set('mail.' . $key, $config);
}
} else {
\Config::set('mail.'.$key, $config);
\Config::set('mail.' . $key, $config);
}
}
}
public function getDriver($driver_id)
{
$short = '';
public function getDriver($driver_id) {
$short = "";
$email_drivers = new \App\Model\MailJob\MailService();
$email_driver = $email_drivers->find($driver_id);
if ($email_driver) {
$short = $email_driver->short_name;
}
return $short;
}
@@ -306,8 +310,7 @@ class EmailsController extends Controller
*
* @return type Response
*/
public function edit($id, Department $department, Help_topic $help, Emails $email, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol)
{
public function edit($id, Department $department, Help_topic $help, Emails $email, Ticket_Priority $ticket_priority, MailboxProtocol $mailbox_protocol) {
try {
$sys_email = \DB::table('settings_email')->select('sys_email')->where('id', '=', 1)->first();
// dd($sys_email);
@@ -319,8 +322,8 @@ class EmailsController extends Controller
$count = $email->count();
// get all the helptopic
$helps = $help->where('status', '=', 1)->get();
// get all active the priority
$priority = $ticket_priority->where('status', '=', 1)->get();
// get all the priority
$priority = $ticket_priority->where('status', '=', 1)->get();
// get all the mailbox protocols
$mailbox_protocols = $mailbox_protocol->get();
@@ -342,8 +345,7 @@ class EmailsController extends Controller
*
* @return int
*/
public function validatingEmailSettingsUpdate($id, MailRequest $request)
{
public function validatingEmailSettingsUpdate($id, MailRequest $request) {
try {
return $this->validatingEmailSettings($request, $id);
} catch (Exception $ex) {
@@ -367,9 +369,9 @@ class EmailsController extends Controller
*
* @return type Response
*/
public function update($id, $request)
{
public function update($id, $request) {
try {
if ($request->sys_email == 'on') {
$system = \DB::table('settings_email')
->where('id', '=', 1)
@@ -395,8 +397,7 @@ class EmailsController extends Controller
*
* @return type Redirect
*/
public function destroy($id, Emails $email)
{
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) {
@@ -410,7 +411,6 @@ class EmailsController extends Controller
$emails = $email->whereId($id)->first();
// checking if deleting the email is success or if it's carrying any dependencies
$emails->delete();
return redirect('emails')->with('success', Lang::get('lang.email_deleted_sucessfully'));
} catch (Exception $e) {
// returns if the try fails
@@ -425,8 +425,7 @@ class EmailsController extends Controller
*
* @return type int
*/
public function getImapStream($request)
{
public function getImapStream($request) {
$host = $request->input('fetching_host');
$port = $request->input('fetching_port');
$service = $request->input('fetching_protocol');
@@ -436,7 +435,7 @@ class EmailsController extends Controller
$password = $request->input('password');
$server = new Fetch($host, $port, $service);
//$server->setFlag('novalidate-cert');
if ($encryption != '') {
if ($encryption != "") {
$server->setFlag($encryption);
}
if (!$validate) {
@@ -447,7 +446,6 @@ class EmailsController extends Controller
$server->setAuthentication($username, $password);
$server->getImapStream();
return 1;
}
@@ -458,8 +456,7 @@ class EmailsController extends Controller
*
* @return type int
*/
public function checkImapStream($imap_stream)
{
public function checkImapStream($imap_stream) {
$check_imap_stream = imap_check($imap_stream);
if ($check_imap_stream) {
$imap_stream = 1;
@@ -477,8 +474,7 @@ class EmailsController extends Controller
*
* @return int
*/
public function getSmtp($request)
{
public function getSmtp($request) {
$sending_status = $request->input('sending_status');
// cheking for the sending protocol
if ($request->input('sending_protocol') == 'smtp') {
@@ -494,8 +490,8 @@ class EmailsController extends Controller
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
];
@@ -527,8 +523,7 @@ class EmailsController extends Controller
*
* @return type string or null
*/
public function departmentValue($dept)
{
public function departmentValue($dept) {
if ($dept) {
$email_department = $dept;
} else {
@@ -545,8 +540,7 @@ class EmailsController extends Controller
*
* @return type string or null
*/
public function priorityValue($priority)
{
public function priorityValue($priority) {
if ($priority) {
$email_priority = $priority;
} else {
@@ -563,8 +557,7 @@ class EmailsController extends Controller
*
* @return type string or null
*/
public function helpTopicValue($help_topic)
{
public function helpTopicValue($help_topic) {
if ($help_topic) {
$email_help_topic = $help_topic;
} else {
@@ -574,20 +567,18 @@ class EmailsController extends Controller
return $email_help_topic;
}
public function emailService($service, $value = [])
{
public function emailService($service, $value = []) {
switch ($service) {
case 'mailgun':
case "mailgun":
$this->setServiceConfig($service, $value);
case 'mandrill':
case "mandrill":
$this->setServiceConfig($service, $value);
case 'ses':
case "ses":
$this->setServiceConfig($service, $value);
}
}
public function setServiceConfig($service, $value)
{
public function setServiceConfig($service, $value) {
//dd($service);
if (count($value) > 0) {
foreach ($value as $k => $v) {
@@ -596,8 +587,7 @@ class EmailsController extends Controller
}
}
public function saveMailService($emailid, $request, $driver)
{
public function saveMailService($emailid, $request, $driver) {
$mail_service = new \App\Model\MailJob\FaveoMail();
$mails = $mail_service->where('email_id', $emailid)->get();
if (count($request) > 0) {
@@ -606,17 +596,16 @@ class EmailsController extends Controller
}
foreach ($request as $key => $value) {
$mail_service->create([
'drive' => $driver,
'key' => $key,
'value' => $value,
'drive' => $driver,
'key' => $key,
'value' => $value,
'email_id' => $emailid,
]);
}
}
}
public function readMails()
{
public function readMails() {
$PhpMailController = new \App\Http\Controllers\Common\PhpMailController();
$NotificationController = new \App\Http\Controllers\Common\NotificationController();
$TicketController = new \App\Http\Controllers\Agent\helpdesk\TicketController($PhpMailController, $NotificationController);
@@ -629,8 +618,7 @@ class EmailsController extends Controller
$controller->readmails($emails, $settings_email, $system, $ticket);
}
public function fetch($email)
{
public function fetch($email) {
$PhpMailController = new \App\Http\Controllers\Common\PhpMailController();
$NotificationController = new \App\Http\Controllers\Common\NotificationController();
$TicketController = new \App\Http\Controllers\Agent\helpdesk\TicketController($PhpMailController, $NotificationController);
@@ -639,26 +627,4 @@ class EmailsController extends Controller
$controller->fetch($email);
}
public function checkMail($request)
{
$mailservice_id = $request->input('sending_protocol');
$driver = $this->getDriver($mailservice_id);
$username = $request->input('email_address');
$password = $request->input('password');
$name = $request->input('email_name');
$host = $request->input('sending_host');
$port = $request->input('sending_port');
$enc = $request->input('sending_encryption');
$service_request = $request->except('sending_status', '_token', 'email_address', 'email_name', 'password', 'department', 'priority', 'help_topic', 'fetching_protocol', 'fetching_host', 'fetching_port', 'fetching_encryption', 'imap_authentication', 'sending_protocol', 'sending_host', 'sending_port', 'sending_encryption', 'smtp_authentication', 'internal_notes', '_wysihtml5_mode');
$this->emailService($driver, $service_request);
$this->setMailConfig($driver, $username, $name, $password, $enc, $host, $port);
$transport = \Swift_SmtpTransport::newInstance($host, $port, $enc);
$transport->setUsername($username);
$transport->setPassword($password);
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->getTransport()->start();
return 1;
}
}