public function getData()
    {
        //return 'kfjhje';
        return Datatable::collection(Category::All())->searchColumns('name')->orderColumns('name', 'description')->addColumn('name', function ($model) {
            return $model->name;
        })->addColumn('Created', function ($model) {
            $t = $model->created_at;
            return TicketController::usertimezone($t);
        })->addColumn('Actions', function ($model) {
            //return '<a href=category/delete/' . $model->id . ' class="btn btn-danger btn-flat">Delete</a>&nbsp;<a href=category/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=article-list class="btn btn-warning btn-flat">View</a>';
            return '<span  data-toggle="modal" data-target="#deletecategory' . $model->slug . '"><a href="#" ><button class="btn btn-danger btn-xs"></a>' . \Lang::get("lang.delete") . '</button></span>&nbsp;<a href=category/' . $model->id . '/edit class="btn btn-warning btn-xs">' . \Lang::get("lang.edit") . '</a>&nbsp;<a href=article-list class="btn btn-primary btn-xs">' . \Lang::get("lang.view") . '</a>
				<div class="modal fade" id="deletecategory' . $model->slug . '">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Are You Sure ?</h4>
                </div>
                <div class="modal-body">
                	' . $model->name . '
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
                    <a href="category/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>';
        })->make();
    }
    /**
     * fetching pages list in chumper datatables
     * @return type
     */
    public function getData()
    {
        /* fetching chumper datatables */
        return Datatable::collection(Page::All())->searchColumns('name')->orderColumns('name', 'description', 'created')->addColumn('name', function ($model) {
            return $model->name;
        })->addColumn('Created', function ($model) {
            $t = $model->created_at;
            return TicketController::usertimezone($t);
        })->addColumn('Actions', function ($model) {
            return '<span  data-toggle="modal" data-target="#deletepage' . $model->id . '"><a href="#" ><button class="btn btn-danger btn-xs"></a> ' . \Lang::get('lang.delete') . '</button></span>&nbsp;<a href=page/' . $model->slug . '/edit class="btn btn-warning btn-xs">' . \Lang::get('lang.edit') . '</a>&nbsp;<a href=pages/' . $model->slug . ' class="btn btn-primary btn-xs">' . \Lang::get('lang.view') . '</a>
				<div class="modal fade" id="deletepage' . $model->id . '">
        			<div class="modal-dialog">
            			<div class="modal-content">
                			<div class="modal-header">
                    			<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    			<h4 class="modal-title">Are You Sure ?</h4>
                			</div>
                			<div class="modal-body">
                				' . $model->name . '
                			</div>
                			<div class="modal-footer">
	                    		<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
    			                <a href="page/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
			                </div>
		            	</div>
			        </div>
    			</div>';
        })->make();
    }
 public function get_inbox()
 {
     return \Datatable::collection(Tickets::where('status', '=', 1)->orderBy('id', 'DESC')->get())->searchColumns('subject')->orderColumns('ticket_number')->addColumn('checkbox', function ($ticket) {
         return "<input type='checkbox' class='icheckbox_flat-blue' name='select_all' value=" . $ticket->id . "/>";
     })->addColumn('name', function ($ticket) {
         $title = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
         $string = strip_tags($title->title);
         if ($title) {
             if ($title == null) {
             } else {
                 $collaborators = Ticket_Collaborator::where('ticket_id', '=', $ticket->id)->get();
                 $collab = count($collaborators);
                 // check atatchments
                 $attachments = Ticket_attachments::where('thread_id', '=', $title->id)->first();
                 $attach = count($attachments);
                 if (strlen($string) > 40) {
                     $stringCut = substr($string, 0, 40);
                     $string = substr($stringCut, 0, strrpos($stringCut, ' ')) . ' ...';
                 }
                 $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
                 $TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
                 $LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
                 if ($LastResponse->role == "user") {
                     $rep = "#F39C12";
                     $username = $LastResponse->user_name;
                 } else {
                     $rep = "#000";
                     $username = $LastResponse->first_name . " " . $LastResponse->last_name;
                     if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
                         $username = $LastResponse->user_name;
                     }
                 }
                 $titles = Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
                 $count = count($titles);
                 foreach ($titles as $title) {
                     $title = $title;
                 }
                 $assigned_to = User::where('id', '=', $ticket->assigned_to)->first();
                 if ($assigned_to == null) {
                     $assigned = "Unassigned";
                 } else {
                     $assigned = $assigned_to->first_name . " " . $assigned_to->last_name;
                 }
                 if ($collab > 0) {
                     $collabs = "&nbsp;<i class='fa fa-users'></i>";
                 }
                 if ($attach > 0) {
                     $attachs = "&nbsp;<i class='fa fa-paperclip'></i>";
                     if ($collab > 0) {
                         $collabs = $collabs . $attachs;
                     } else {
                         $collabs = $attachs;
                     }
                 }
                 return "<a href=" . route('ticket.thread', [$ticket->id]) . " title=" . $title->title . ">" . $string . "</a> (" . $count . ") <i class='fa fa-comment'></i>\n                        " . $collab;
             }
         }
     })->addColumn('Ticket ID', function ($ticket) {
         $ticket_number = "<a href='" . route('ticket.thread', [$ticket->id]) . "' title=''># " . $ticket->ticket_number . "</a>";
         return $ticket_number;
     })->addColumn('Priority', function ($ticket) {
         $priority = Ticket_Priority::where('priority_id', '=', $ticket->priority_id)->first();
         return "<td class='mailbox-priority'><spam style='color:green;'>" . $priority->priority_desc . "</spam></td>";
         // return TicketController::usertimezone($st);
     })->addColumn('From', function ($ticket) {
         $from = User::where('id', '=', $ticket->user_id)->first();
         if ($from->role == "user") {
             return $from->user_name;
         } else {
             return $from->first_name . " " . $from->last_name;
         }
     })->addColumn('Last Replier', function ($ticket) {
         $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
         $TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
         $LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
         if ($LastResponse->role == "user") {
             $rep = "#F39C12";
             $username = $LastResponse->user_name;
         } else {
             $rep = "#000";
             $username = $LastResponse->first_name . " " . $LastResponse->last_name;
             if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
                 $username = $LastResponse->user_name;
             }
         }
         return $username;
     })->addColumn('Assigned To', function ($ticket) {
         $assigned_to = User::where('id', '=', $ticket->assigned_to)->first();
         if ($assigned_to == null) {
             $assigned = "Unassigned";
         } else {
             $assigned = $assigned_to->first_name . " " . $assigned_to->last_name;
         }
         return $assigned;
     })->addColumn('Last Activity', function ($ticket) {
         $assigned_to = User::where('id', '=', $ticket->assigned_to)->first();
         if ($assigned_to == null) {
             $assigned = "Unassigned";
         } else {
             $assigned = $assigned_to->first_name . " " . $assigned_to->last_name;
         }
         return $assigned;
     })->addColumn('Last Activity', function ($ticket) {
         $titles = Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
         $count = count($titles);
         foreach ($titles as $title) {
             $title = $title;
         }
         return TicketController::usertimezone($title->created_at);
     })->make();
 }
 /**
  * getdata
  * @return type 
  */
 public function getData()
 {
     return \Datatable::collection(Comment::All())->searchColumns('name', 'email', 'comment', 'created')->orderColumns('name')->addColumn('name', function ($model) {
         return $model->name;
     })->addColumn('email', function ($model) {
         return $model->email;
     })->addColumn('website', function ($model) {
         return $model->website;
     })->addColumn('comment', function ($model) {
         return $model->comment;
     })->addColumn('status', function ($model) {
         $status = $model->status;
         if ($status == 1) {
             return '<p style="color:blue"">' . \Lang::get('lang.published');
         } else {
             return '<p style="color:red"">' . \Lang::get('lang.not_published');
         }
     })->addColumn('Created', function ($model) {
         return TicketController::usertimezone(date($model->created_at));
     })->addColumn('Actions', function ($model) {
         return '<a href=comment/delete/' . $model->id . ' class="btn btn-danger btn-xs">' . \Lang::get('lang.delete') . '</a>&nbsp;<a href=published/' . $model->id . ' class="btn btn-warning btn-xs">' . \Lang::get('lang.publish') . '</a>';
     })->make();
 }
    /**
     * This function is used to display the list of users
     * @return datatable
     */
    public function user_list()
    {
        return \Datatable::collection(User::where('role', '!=', 'admin')->where('role', '!=', 'agent')->get())->searchColumns('user_name')->orderColumns('user_name', 'email')->addColumn('user_name', function ($model) {
            return $model->user_name;
        })->addColumn('email', function ($model) {
            $email = $model->email;
            return $email;
        })->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;
        })->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;
        })->addColumn('lastlogin', function ($model) {
            $t = $model->updated_at;
            return TicketController::usertimezone($t);
        })->addColumn('Actions', function ($model) {
            //return '<a href=article/delete/ ' . $model->id . ' class="btn btn-danger btn-flat" onclick="myFunction()">Delete</a>&nbsp;<a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=show/' . $model->id . ' class="btn btn-warning btn-flat">View</a>';
            //return '<form action="article/delete/ ' . $model->id . '" method="post" onclick="alert()"><button type="sumbit" value="Delete"></button></form><a href=article/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a>&nbsp;<a href=show/' . $model->id . ' class="btn btn-warning btn-flat">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="' . 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>
				<div class="modal fade" id="deletearticle' . $model->id . '">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Are You Sure ?</h4>
                </div>
                <div class="modal-body">
                ' . $model->user_name . '
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
                    <a href="' . route('user.delete', $model->id) . '"><button class="btn btn-danger">delete</button></a>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>';
        })->make();
    }
 /**
  * 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())->searchColumns('user_name')->orderColumns('user_name', 'email')->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 = $model->user_name;
         }
         return $username;
     })->addColumn('email', function ($model) {
         $email = $model->email;
         return $email;
     })->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;
     })->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;
     })->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;
     })->addColumn('lastlogin', function ($model) {
         $t = $model->updated_at;
         return TicketController::usertimezone($t);
     })->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();
 }