Exemplo n.º 1
0
 public function destroy(ServiceTime $service_time)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $service_time->delete();
     return redirect('/configuration#service_time')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 2
0
 public function destroy(TicketType $ticket_type)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $ticket_type->delete();
     return redirect('/configuration#ticket')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 3
0
 public function destroy(Department $department)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $department->delete();
     return redirect('/configuration#department')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 4
0
 public function destroy(BusinessHour $business_hour)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $business_hour->delete();
     return redirect('/configuration#business_hour')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 5
0
 public function store(InstallRequest $request)
 {
     $url = "http://verify.wmlab.in/index.php?envato_username="******"&purchase_code=" . $request->input('purchase_code') . "&product=" . config('constants.ITEM_CODE');
     if (!file_get_contents($url)) {
         return redirect()->back()->withInput()->withErrors("We can't verify you as our customer.");
     }
     if (!is_writable('../config/database.php')) {
         return redirect()->back()->withInput()->withErrors('database.php file is not writable.');
     } else {
         $link = @mysqli_connect($request->input('hostname'), $request->input('mysql_username'), $request->input('mysql_password'));
         if (!$link) {
             return redirect()->back()->withInput()->withErrors('Connection could not be established.');
         } else {
             mysqli_select_db($link, $request->input('mysql_database'));
             if (!is_file('../database/database.sql')) {
                 return redirect()->back()->withInput()->withErrors('Database file not found.');
             } else {
                 $templine = '';
                 $lines = file('../database/database.sql');
                 foreach ($lines as $line) {
                     if (substr($line, 0, 2) == '--' || $line == '') {
                         continue;
                     }
                     $templine .= $line;
                     if (substr(trim($line), -1, 1) == ';') {
                         mysqli_query($link, $templine) or print 'Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />';
                         $templine = '';
                     }
                 }
                 $username = $request->input('username');
                 $password = bcrypt($request->input('password'));
                 $email = $request->input('email');
                 mysqli_query($link, "insert into roles(name,display_name) values('admin','Admin'),('user','User'),('staff','Staff') ");
                 mysqli_query($link, "insert into departments(department_name) values('Support')");
                 mysqli_query($link, "insert into users(email,username,password,confirmed) values('{$email}','{$username}','{$password}','1') ");
                 mysqli_query($link, "insert into profile(user_id,department_id) values('1','1') ");
                 mysqli_query($link, "insert into role_user(user_id,role_id) values('1','1') ");
                 $db_file = file_get_contents('../config/database.php');
                 $db_file = str_replace('%hostname%', $request->input('hostname'), $db_file);
                 $db_file = str_replace('%mysql_username%', $request->input('mysql_username'), $db_file);
                 $db_file = str_replace('%mysql_password%', $request->input('mysql_password'), $db_file);
                 $db_file = str_replace('%mysql_database%', $request->input('mysql_database'), $db_file);
                 file_put_contents('../config/database.php', $db_file);
                 $config = Helper::getConfiguration();
                 $config['installation_path'] = '0';
                 $filename = base_path() . config('paths.CONFIG_PATH');
                 File::put($filename, var_export($config, true));
                 File::prepend($filename, '<?php return ');
                 File::append($filename, ';');
                 return redirect('/')->withSuccess('Installed successfully.');
             }
         }
     }
 }
Exemplo n.º 6
0
 public function destroy(Role $role)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     if ($role->name == 'admin') {
         return redirect('/configuration#permission')->withErrors(config('constants.INVALID_LINK'));
     }
     $role->delete();
     return redirect()->back()->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 7
0
 public function destroy(CustomField $custom_field)
 {
     if (!Entrust::can('manage_custom_field')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $custom_field->delete();
     $activity = 'Deleted a Custome Field';
     Activity::log($activity);
     return redirect('/custom_field')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 8
0
 public function destroy(Attachment $attachment)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     if ($attachment->user_id != Auth::user()->id && !Entrust::hasRole('admin')) {
         return redirect()->back()->withErrors(config('constants.INVALID_LINK'));
     }
     $belongs_to = $attachment->belongs_to;
     File::delete('uploads/attachment_files/' . $attachment->file);
     $attachment->delete($id);
     $activity = 'Deleted a file on a ' . $belongs_to;
     Activity::log($activity);
     return redirect()->back()->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 9
0
 public function destroy(Annoucement $annoucement)
 {
     if (!Entrust::can('delete_annoucement')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     Helper::deleteCustomField($this->form, $annoucement->id);
     $annoucement->delete();
     $activity = 'Deleted a annoucement';
     Activity::log($activity);
     return redirect('/annoucement')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 10
0
 public function delete($id, $token)
 {
     if (!Entrust::can('manage_message')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::verifyCsrf($token)) {
         return redirect('/dashboard')->withErrors(config('constants.CSRF'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $message = Message::find($id);
     if (!$message || $message->to_user_id != Auth::user()->id && $message->from_user_id != Auth::user()->id) {
         return redirect('/message')->withErrors(config('constants.INVALID_LINK'));
     }
     if ($message->to_user_id == Auth::user()->id) {
         $message->delete_receiver = 1;
     } else {
         $message->delete_sender = 1;
     }
     $message->save();
     return redirect('/message')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 11
0
 public function PUT_updateUser(Request $request, $id)
 {
     $theme = Theme::uses('notebook')->layout('default');
     $theme->setMenu('user.user');
     $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required_with:password|min:6', 'name' => 'required', 'groups' => 'required|array']);
     $errors = array();
     if ($validator->fails()) {
         foreach ($validator->errors()->all() as $message) {
             $errors[] = $message;
         }
     }
     if (!count($errors)) {
         $chk = User::where('email', $request->input('email'))->where('id', '!=', $id)->count();
         if ($chk) {
             $errors[] = 'User with this email already exists.';
         }
     }
     if (!count($errors)) {
         $user = User::find($id);
         $user->email = $request->input('email');
         $user->name = $request->input('name');
         if ($request->has('password')) {
             $user->password = bcrypt($request->input('password'));
         }
         $user->save();
         $ug = UserGroup::where('user_id', $id);
         $ug->delete();
         $groups = $request->input('groups');
         if (is_array($groups)) {
             foreach ($groups as $key => $group) {
                 $adminGroup = Group::find($group);
                 $usergroup = UserGroup::create(array('user_id' => $user->id, 'group_id' => $adminGroup->id));
             }
         }
         return redirect(route('user.list'))->with('STATUS_OK', 'User `' . $request->input('email') . '` successfully updated.');
     } else {
         $msg = Helper::arrayToList($errors);
         return redirect(route('user.update', $id))->with('STATUS_FAIL', $msg)->withInput();
     }
 }
Exemplo n.º 12
0
 public function destroy(Ticket $ticket)
 {
     if (!Entrust::can('delete_ticket')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     Helper::deleteCustomField($this->form, $ticket->id);
     $ticket_no = $ticket->ticket_no;
     $ticket->delete();
     $activity = 'Deleted a ticket # ' . $ticket_no;
     Activity::log($activity);
     return redirect('/ticket')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 13
0
 public function store(Request $request)
 {
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $config = Helper::getConfiguration();
     $config_type = $request->input('config_type');
     $input = $request->all();
     foreach ($input as $key => $value) {
         if ($key != '_token' && $key != 'config_type') {
             $config[$key] = $value;
         }
     }
     if ($request->input('next_ticket_no')) {
         $max_ticket_no = \App\Ticket::max('ticket_no');
         if (isset($max_ticket_no) && $request->input('next_ticket_no') < $max_ticket_no) {
             return redirect()->back()->withErrors('Next ticket number cannot be less than existing ticket number.');
         }
     }
     $filename = base_path() . config('paths.CONFIG_PATH');
     File::put($filename, var_export($config, true));
     File::prepend($filename, '<?php return ');
     File::append($filename, ';');
     return redirect('/configuration#' . $config_type)->withSuccess(config('constants.SAVED'));
 }
Exemplo n.º 14
0
 public function postRegister(RegisterRequest $request, User $user)
 {
     if (!Entrust::can('create_user')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     $user->fill($request->all());
     $user->password = bcrypt($request->input('password'));
     $key = config('app.key');
     $user->confirmation_code = hash_hmac('sha256', str_random(40), $key);
     $user->confirmed = 1;
     $user->save();
     $profile = new Profile();
     $profile->user()->associate($user);
     $profile->department_id = $request->input('department_id') ?: null;
     $profile->save();
     $user->attachRole($request->input('role_id'));
     Helper::storeCustomField('user-form', $user->id, $request->all());
     $path = base_path() . '/config/template/' . config('config.domain') . '/new_user';
     $content = '';
     if (File::exists($path)) {
         $content = File::get($path);
     }
     $content = Helper::templateContent($content, 'user', $user);
     $content = str_replace('[PASSWORD]', $request->input('password'), $content);
     if ($content != '' && $request->input('send_mail')) {
         $title = Helper::templateContent(config('template.new_user.title'), 'user', $user);
         Mail::send('template.mail', compact('content'), function ($message) use($user, $title) {
             $message->to($user->email)->subject($title);
         });
     }
     $activity = Auth::user()->name . ' created a User (' . $user->name . ')';
     Activity::log($activity);
     return redirect()->back()->withSuccess('User created successfully. ');
 }
Exemplo n.º 15
0
 public function POST_createGroup(Request $request)
 {
     $validator = Validator::make($request->all(), ['group_name' => 'required', 'routes' => 'required|array']);
     $errors = array();
     if ($validator->fails()) {
         foreach ($validator->errors()->all() as $message) {
             $errors[] = $message;
         }
     }
     if (!count($errors)) {
         $chk = Group::where('name', $request->input('group_name'))->count();
         if ($chk) {
             $errors[] = 'Group `' . $request->input('group_name') . '` already exists.';
         }
     }
     if (!count($errors)) {
         $ar_grps = $request->input('routes');
         $ar_groups = array();
         if (is_array($ar_grps)) {
             foreach ($ar_grps as $key => $grp) {
                 $ar_groups[$grp] = 1;
             }
         }
         // $group = Group::create(array(
         $group = new Group();
         $group->name = $request->input('group_name');
         $group->permissions = json_encode($ar_groups);
         $group->save();
         return redirect(route('group.assign'))->with('STATUS_OK', 'Group `' . $request->input('group_name') . '` successfully created.');
     } else {
         $msg = Helper::arrayToList($errors);
         return redirect(route('group.create'))->with('STATUS_FAIL', $msg)->withInput();
     }
 }
Exemplo n.º 16
0
 public function destroy(User $user)
 {
     if (!Entrust::can('delete_user')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     if ($user->id == Auth::user()->id) {
         return redirect('/user')->withErrors('You cannot delete yourself. ');
     }
     Helper::deleteCustomField($this->form, $user->id);
     $user->delete();
     return redirect('/user')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 17
0
 public function welcomeEmail($user_id, $token)
 {
     if (!Entrust::can('send_welcome_email')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::verifyCsrf($token)) {
         return redirect('/dashboard')->withErrors(config('constants.CSRF'));
     }
     $user = \App\User::find($user_id);
     $filename = base_path() . '/config/template/' . DOMAIN . '/welcome_mail';
     $content = File::get($filename);
     if (!$user) {
         return redirect()->back()->withErrors(config('constants.INVALID_LINK'));
     }
     $content = str_replace('[NAME]', $user->name, $content);
     $content = str_replace('[EMAIL]', $user->email, $content);
     $content = str_replace('[USERNAME]', $user->username, $content);
     Mail::send('template.mail', compact('content'), function ($message) use($user) {
         $message->to($user->email)->subject('Welcome');
     });
     return redirect()->back()->withSuccess('Mail send successfully.');
 }
Exemplo n.º 18
0
 public function destroy(Holiday $holiday)
 {
     if (!Entrust::can('delete_holiday')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     Helper::deleteCustomField($this->form, $holiday->id);
     $holiday->delete();
     return redirect('/holiday')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 19
0
 public function destroy($id)
 {
     if (!Entrust::can('manage_language')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $languages = Helper::getAllLanguages();
     if (!array_key_exists($id, $languages)) {
         return redirect()->back()->withErrors(config('constants.INVALID_LINK'));
     }
     if ($id == 'en') {
         return redirect('/language')->withErrors('You cannot delete primary language.');
     }
     if (config('config.default_language') == $id) {
         return redirect('/language')->withErrors('This language is currently default language of system, Please change system language.');
     }
     $result = File::deleteDirectory(base_path() . '/resources/lang/' . $id);
     unset($languages[$id]);
     $filename = base_path() . config('paths.LANG_PATH');
     File::put($filename, var_export($languages, true));
     File::prepend($filename, '<?php return ');
     File::append($filename, ';');
     $activity = 'Deleted a Language';
     Activity::log($activity);
     return redirect('/language')->withSuccess(config('constants.DELETED'));
 }
Exemplo n.º 20
0
 public function index(Request $request)
 {
     $start_date = $request->input('start_date') ?: date('Y-m-d', strtotime('-30 days'));
     $end_date = $request->input('end_date') ?: date('Y-m-d', strtotime(date('Y-m-d')));
     if (Entrust::hasRole('user')) {
         return redirect('/')->withErrors(config('constants.NA'));
     }
     $user_count = \App\User::with('roles')->whereHas('roles', function ($query) {
         $query->whereName('user');
     })->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $staff_count = \App\User::with('roles')->whereHas('roles', function ($query) {
         $query->where('name', '!=', 'user');
     })->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $ticket_count = \App\Ticket::where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $closed_ticket_count = \App\Ticket::where('ticket_status', '=', 'close')->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $closed_ticket_percentage = $ticket_count > 0 ? round($closed_ticket_count / $ticket_count * 100, 2) : 0;
     $ticket_status_stats = \App\Ticket::select('ticket_status', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('ticket_status')->get();
     $status_stats = array();
     foreach ($ticket_status_stats as $stat) {
         $status_stats[] = array('label' => Helper::toWord($stat->ticket_status), 'value' => $stat->total);
     }
     $ticket_priority_stats = \App\Ticket::select('ticket_priority', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('ticket_priority')->get();
     $priority_stats = array();
     foreach ($ticket_priority_stats as $stat) {
         $priority_stats[] = array('label' => Helper::toWord($stat->ticket_priority), 'value' => $stat->total);
     }
     $ticket_type_status = \App\Ticket::select('ticket_type_id', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('ticket_type_id')->get();
     $type_stats = array();
     foreach ($ticket_type_status as $stat) {
         $type_stats[] = array('label' => Helper::toWord($stat->TicketType->ticket_type_name), 'value' => $stat->total);
     }
     $ticket_department_stats = \App\Ticket::select('department_id', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('department_id')->get();
     $department_stats = array();
     foreach ($ticket_department_stats as $stat) {
         $department_stats[] = array('label' => Helper::toWord($stat->Department->department_name), 'value' => $stat->total);
     }
     $users = \App\User::with('roles')->whereHas('roles', function ($query) {
         $query->where('name', '!=', 'user');
     })->where('id', '!=', Auth::user()->id)->get();
     $user_list = array();
     foreach ($users as $user) {
         $user_list[$user->id] = $user->name . ' (Department : ' . $user->Profile->Department->department_name . ')';
     }
     $query = DB::table('activity_log')->join('users', 'users.id', '=', 'activity_log.user_id')->select(DB::raw('name,activity_log.created_at AS created_at,text,user_id'));
     if (!Entrust::hasRole('admin')) {
         $query->where('user_id', '=', Auth::user()->id);
     }
     $activities = $query->latest()->limit(100)->get();
     $holidays = \App\Holiday::all();
     $todos = \App\Todo::where('user_id', '=', Auth::user()->id)->orWhere(function ($query) {
         $query->where('user_id', '!=', Auth::user()->id)->where('visibility', '=', 'public');
     })->get();
     $events = array();
     foreach ($holidays as $holiday) {
         $start = $holiday->date;
         $title = 'Holiday: ' . $holiday->holiday_description;
         $color = '#1e5400';
         $events[] = array('title' => $title, 'start' => $start, 'color' => $color);
     }
     foreach ($todos as $todo) {
         $start = $todo->date;
         $title = 'To do: ' . $todo->todo_title . ' ' . $todo->todo_description;
         $color = '#ff0000';
         $url = '/todo/' . $todo->id . '/edit';
         $events[] = array('title' => $title, 'start' => $start, 'color' => $color, 'url' => $url);
     }
     $colors = ['#5CB85C', '#FFD600', '#D10D0D', '#1A89E8', '#458b00', '#f85931', '#ce1836', '#009989', '#00688b', '#8b1a1a'];
     shuffle($colors);
     $status_colors = $colors;
     shuffle($colors);
     $priority_colors = $colors;
     shuffle($colors);
     $type_colors = $colors;
     shuffle($colors);
     $department_colors = $colors;
     $assets = ['calendar', 'graph'];
     return view('dashboard', compact('user_count', 'staff_count', 'assets', 'activities', 'user_list', 'holidays', 'events', 'ticket_count', 'closed_ticket_percentage', 'status_stats', 'priority_stats', 'type_stats', 'department_stats', 'status_colors', 'priority_colors', 'type_colors', 'department_colors', 'start_date', 'end_date'));
 }
Exemplo n.º 21
0
 public static function inWords($number)
 {
     $hyphen = '-';
     $conjunction = ' and ';
     $separator = ', ';
     $negative = 'negative ';
     $decimal = ' point ';
     $dictionary = array(0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'fourty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety', 100 => 'hundred', 1000 => 'thousand', 1000000 => 'million', 1000000000 => 'billion', 1000000000000 => 'trillion', 1000000000000000 => 'quadrillion', 1000000000000000000 => 'quintillion');
     if (!is_numeric($number)) {
         return false;
     }
     if ($number >= 0 && (int) $number < 0 || (int) $number < 0 - PHP_INT_MAX) {
         // overflow
         trigger_error('convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING);
         return false;
     }
     if ($number < 0) {
         return $negative . Helper::inWords(abs($number));
     }
     $string = $fraction = null;
     if (strpos($number, '.') !== false) {
         list($number, $fraction) = explode('.', $number);
     }
     switch (true) {
         case $number < 21:
             $string = $dictionary[$number];
             break;
         case $number < 100:
             $tens = (int) ($number / 10) * 10;
             $units = $number % 10;
             $string = $dictionary[$tens];
             if ($units) {
                 $string .= $hyphen . $dictionary[$units];
             }
             break;
         case $number < 1000:
             $hundreds = $number / 100;
             $remainder = $number % 100;
             $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
             if ($remainder) {
                 $string .= $conjunction . Helper::inWords($remainder);
             }
             break;
         default:
             $baseUnit = pow(1000, floor(log($number, 1000)));
             $numBaseUnits = (int) ($number / $baseUnit);
             $remainder = $number % $baseUnit;
             $string = Helper::inWords($numBaseUnits) . ' ' . $dictionary[$baseUnit];
             if ($remainder) {
                 $string .= $remainder < 100 ? $conjunction : $separator;
                 $string .= Helper::inWords($remainder);
             }
             break;
     }
     if (null !== $fraction && is_numeric($fraction)) {
         $string .= $decimal;
         $words = array();
         foreach (str_split((string) $fraction) as $number) {
             $words[] = $dictionary[$number];
         }
         $string .= implode(' ', $words);
     }
     return $string;
 }