update v1.0.7.9 R.C.

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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