public function getGenerateManual($role_name = NULL)
 {
     $permission_array = \Login::get_role_permissions($role_name);
     $array = ['role_name' => $role_name];
     $array['title'] = 'Manual de Administrador';
     $array['header_title'] = 'Manual de Administrador';
     $array['site'] = \Solunes\Master\App\Site::find(1);
     $array['nodes'] = \Solunes\Master\App\Node::whereNull('parent_id')->whereIn('permission', $permission_array)->with('fields', 'children.fields', 'children.children.fields')->get();
     $pdf = \PDF::loadView('master::pdf.manual', $array);
     $header = \View::make('pdf.header', $array);
     return $pdf->setPaper('letter')->setOption('header-html', $header->render())->stream(trans('master::admin.manual') . '_' . date('Y-m-d') . '.pdf');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // General
     \Solunes\Master\App\Language::create(['code' => 'es', 'name' => 'Español', 'image' => 'es.png']);
     \Solunes\Master\App\Site::create(['name' => 'Plataforma', 'domain' => 'http://master.dev/', 'root' => '/', 'google_verification' => '', 'analytics' => '']);
     // Nodos
     $node_node = \Solunes\Master\App\Node::create(['name' => 'node', 'folder' => 'system']);
     $node_node_requests = \Solunes\Master\App\Node::create(['name' => 'node-request', 'location' => 'package', 'type' => 'subchild', 'parent_id' => $node_node->id]);
     $node_node_extras = \Solunes\Master\App\Node::create(['name' => 'node-extra', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_node->id]);
     $node_filter = \Solunes\Master\App\Node::create(['name' => 'filter', 'folder' => 'system']);
     $node_field = \Solunes\Master\App\Node::create(['name' => 'field', 'type' => 'child', 'location' => 'package', 'parent_id' => $node_node->id]);
     $node_field_extras = \Solunes\Master\App\Node::create(['name' => 'field-extra', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_field->id]);
     $node_field_conditional = \Solunes\Master\App\Node::create(['name' => 'field-conditional', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_field->id]);
     $node_indicator = \Solunes\Master\App\Node::create(['name' => 'indicator', 'folder' => 'system', 'customized' => 1]);
     $node_indicator_alert = \Solunes\Master\App\Node::create(['name' => 'indicator-alert', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_indicator->id]);
     $node_indicator_graph = \Solunes\Master\App\Node::create(['name' => 'indicator-graph', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_indicator->id]);
     $node_indicator_value = \Solunes\Master\App\Node::create(['name' => 'indicator-value', 'type' => 'child', 'location' => 'package', 'parent_id' => $node_indicator->id]);
     $node_site = \Solunes\Master\App\Node::create(['name' => 'site', 'folder' => 'global']);
     $node_page = \Solunes\Master\App\Node::create(['name' => 'page', 'folder' => 'global']);
     $node_menu = \Solunes\Master\App\Node::create(['name' => 'menu', 'folder' => 'global']);
     $node_section = \Solunes\Master\App\Node::create(['name' => 'section', 'folder' => 'global']);
     $node_permission = \Solunes\Master\App\Node::create(['name' => 'permission', 'folder' => 'system']);
     $node_role = \Solunes\Master\App\Node::create(['name' => 'role', 'folder' => 'system']);
     $node_permission_role = \Solunes\Master\App\Node::create(['name' => 'permission-role', 'table_name' => 'permission_role', 'location' => 'package', 'type' => 'field', 'model' => '\\Solunes\\Master\\App\\Permission', 'parent_id' => $node_role->id]);
     $node_user = \Solunes\Master\App\Node::create(['name' => 'user', 'location' => 'app', 'folder' => 'global']);
     \Solunes\Master\App\Filter::create(['node_id' => $node_user->id, 'parameter' => 'status']);
     $node_role_user = \Solunes\Master\App\Node::create(['name' => 'role-user', 'table_name' => 'role_user', 'location' => 'package', 'type' => 'field', 'model' => '\\Solunes\\Master\\App\\Role', 'parent_id' => $node_user->id]);
     $node_email = \Solunes\Master\App\Node::create(['name' => 'email', 'folder' => 'global']);
     $node_activity = \Solunes\Master\App\Node::create(['name' => 'activity', 'table_name' => 'activities', 'folder' => 'system']);
     $node_notification = \Solunes\Master\App\Node::create(['name' => 'notification', 'folder' => 'system']);
     $node_inbox = \Solunes\Master\App\Node::create(['name' => 'inbox', 'table_name' => 'inbox', 'folder' => 'system']);
     $node_inbox_users = \Solunes\Master\App\Node::create(['name' => 'inbox-user', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_inbox->id]);
     $node_inbox_messages = \Solunes\Master\App\Node::create(['name' => 'inbox-message', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_inbox->id]);
     $node_variable = \Solunes\Master\App\Node::create(['name' => 'variable', 'folder' => 'global']);
     $node_image_folder = \Solunes\Master\App\Node::create(['name' => 'image-folder', 'folder' => 'system']);
     $node_image_size = \Solunes\Master\App\Node::create(['name' => 'image-size', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_image_folder->id]);
     $node_temp_file = \Solunes\Master\App\Node::create(['name' => 'temp-file', 'folder' => 'system']);
     // Usuarios
     $admin = \Solunes\Master\App\Role::create(['name' => 'admin', 'display_name' => 'Admin']);
     $member = \Solunes\Master\App\Role::create(['name' => 'member', 'display_name' => 'Miembro']);
     $system_perm = \Solunes\Master\App\Permission::create(['name' => 'system', 'display_name' => 'Sistema']);
     $global_perm = \Solunes\Master\App\Permission::create(['name' => 'global', 'display_name' => 'Global']);
     $site_perm = \Solunes\Master\App\Permission::create(['name' => 'site', 'display_name' => 'Site']);
     $form_perm = \Solunes\Master\App\Permission::create(['name' => 'form', 'display_name' => 'Formulario']);
     $dashboard_perm = \Solunes\Master\App\Permission::create(['name' => 'dashboard', 'display_name' => 'Dashboard']);
     $admin->permission_role()->sync([$global_perm->id, $site_perm->id, $form_perm->id, $dashboard_perm->id]);
     // Tamaños de archivos
     \Solunes\Master\App\Variable::create(['name' => 'image_size', 'type' => 'string', 'es' => ['value' => '5']]);
     \Solunes\Master\App\Variable::create(['name' => 'file_size', 'type' => 'string', 'es' => ['value' => '10']]);
     \Solunes\Master\App\Variable::create(['name' => 'image_extension', 'type' => 'string', 'es' => ['value' => 'jpg,jpeg,png,gif']]);
     \Solunes\Master\App\Variable::create(['name' => 'file_extension', 'type' => 'string', 'es' => ['value' => 'doc,docx,xls,xlsx,ppt,pptx,pdf,txt,jpg,jpeg,png,gif']]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \Solunes\Master\App\ImageSize::truncate();
     \Solunes\Master\App\ImageFolder::truncate();
     \Solunes\Master\App\TempFile::truncate();
     \Solunes\Master\App\VariableTranslation::truncate();
     \Solunes\Master\App\Variable::truncate();
     \Solunes\Master\App\InboxUser::truncate();
     \Solunes\Master\App\InboxMessage::truncate();
     \Solunes\Master\App\Inbox::truncate();
     \Solunes\Master\App\Notification::truncate();
     \Solunes\Master\App\Activity::truncate();
     DB::table('permission_role')->truncate();
     DB::table('role_user')->truncate();
     \Solunes\Master\App\Role::truncate();
     \Solunes\Master\App\Permission::truncate();
     \App\User::truncate();
     \Solunes\Master\App\EmailTranslation::truncate();
     \Solunes\Master\App\Email::truncate();
     \Solunes\Master\App\IndicatorValue::truncate();
     \Solunes\Master\App\IndicatorGraph::truncate();
     \Solunes\Master\App\IndicatorAlert::truncate();
     \Solunes\Master\App\Indicator::truncate();
     \Solunes\Master\App\FieldOptionTranslation::truncate();
     \Solunes\Master\App\FieldOption::truncate();
     \Solunes\Master\App\FieldConditional::truncate();
     \Solunes\Master\App\FieldExtra::truncate();
     \Solunes\Master\App\FieldTranslation::truncate();
     \Solunes\Master\App\Field::truncate();
     \Solunes\Master\App\Section::truncate();
     \Solunes\Master\App\Filter::truncate();
     \Solunes\Master\App\NodeExtra::truncate();
     \Solunes\Master\App\NodeRequest::truncate();
     \Solunes\Master\App\NodeTranslation::truncate();
     \Solunes\Master\App\Node::truncate();
     \Solunes\Master\App\MenuTranslation::truncate();
     \Solunes\Master\App\Menu::truncate();
     \Solunes\Master\App\PageTranslation::truncate();
     \Solunes\Master\App\Page::truncate();
     \Solunes\Master\App\SiteTranslation::truncate();
     \Solunes\Master\App\Site::truncate();
     \Solunes\Master\App\Language::truncate();
     \App\PasswordReminder::truncate();
 }
 public function boot(ViewFactory $view)
 {
     parent::boot($view);
     view()->composer(['layouts.master', 'master::layouts.admin'], function ($view) {
         $array['site'] = \Solunes\Master\App\Site::with('translations')->where('id', 1)->first();
         if (auth()->check()) {
             $array['alerts'] = \Solunes\Master\App\IndicatorAlert::where('user_id', auth()->user()->id)->has('indicator')->with('indicator', 'indicator.indicator_values')->get();
             $array['inbox'] = \Solunes\Master\App\Inbox::whereHas('inbox_users', function ($q) {
                 $q->where('user_id', auth()->user()->id);
             })->with('other_users', 'last_message')->orderBy('updated_at', 'DESC')->limit(10)->get();
             $array['notifications'] = \Solunes\Master\App\Notification::where('user_id', auth()->user()->id)->orderBy('created_at', 'DESC')->limit(10)->get();
         }
         if (request()->has('download-pdf')) {
             $array['pdf'] = true;
         } else {
             $array['pdf'] = false;
         }
         $view->with($array);
     });
 }
 public static function get_request($single_model, $action, $id, $data, $options = [], $additional_vars = NULL)
 {
     $node = \Solunes\Master\App\Node::where('name', $single_model)->first();
     $model = \FuncNode::node_check_model($node);
     if (\Gate::denies('node-admin', ['item', $data->module, $node, $action, $id])) {
         return \Login::redirect_dashboard('no_permission');
     }
     if ($action == 'delete' || $action == 'restore') {
         if ($node->soft_delete == 1) {
             $item = $model->withTrashed()->where('id', $id)->first();
         } else {
             $item = $model->find($id);
         }
         if ($item) {
             if ($node->soft_delete == 0 && $action == 'delete') {
                 $file_fields = $node->fields()->whereIn('type', ['image', 'file'])->get();
                 \Asset::delete_saved_files($file_fields, $item);
                 if (count($node->children) > 0) {
                     foreach ($node->children as $child) {
                         $child_name = $child->table_name;
                         $file_fields = $child->fields()->whereIn('type', ['image', 'file'])->get();
                         if (is_object($item->{$child_name}) && count($item->{$child_name}) > 0) {
                             foreach ($item->{$child_name} as $item_child) {
                                 \Asset::delete_saved_files($file_fields, $item_child);
                             }
                         } else {
                             \Asset::delete_saved_files($file_fields, $item->{$child_name});
                         }
                     }
                 }
             }
             $item->{$action}();
             return redirect($data->prev)->with('message_success', trans('admin.' . $action . '_success'));
         } else {
             return redirect($data->prev)->with('message_fail', trans('admin.' . $action . '_fail'));
         }
     } else {
         $variables = \AdminItem::get_request_variables($data->module, $node, $model, $single_model, $action, $id, $options, $additional_vars);
         $view = 'master::item.model';
         if ($variables['preset_field'] === true) {
             if ($node->name == 'indicator') {
                 if (\View::exists('includes.select-parent-indicator')) {
                     $view = 'includes.select-parent-indicator';
                 } else {
                     $view = 'master::includes.select-parent-indicator';
                 }
             } else {
                 $view = 'master::includes.select-parent';
             }
         } else {
             if ($node->customized) {
                 $custom_location = 'item.';
                 if ($node->name == 'indicator') {
                     $custom_location = 'master::' . $custom_location;
                 }
                 $view = $custom_location . $single_model;
             }
         }
         if (request()->has('download-pdf')) {
             $variables['pdf'] = true;
             $variables['dt'] = 'view';
             $variables['header_title'] = \CustomFunc::custom_pdf_header($node, $id);
             $variables['title'] = 'Formulario de ' . $node->singular;
             $variables['site'] = \Solunes\Master\App\Site::find(1);
             $pdf = \PDF::loadView($view, $variables);
             $header = \View::make('pdf.header', $variables);
             return $pdf->setPaper('letter')->setOption('header-html', $header->render())->stream($node->singular . '_' . date('Y-m-d') . '.pdf');
         } else {
             return view($view, $variables);
         }
     }
 }