public function createAdmin()
 {
     if (\Input::get("password") == \Input::get("passwordrepeat")) {
         if (\Neyko\Admin\Model\Administrator::where("username", "=", \Input::get("username"))->orWhere("email", "=", \Input::get("email"))->count() < 1) {
             $admin = \Neyko\Admin\Model\Administrator::create(array("username" => \Input::get("username"), "password" => \Hash::make(\Input::get("password")), "email" => \Input::get("email"), "lang" => \Input::get("language")));
             $admin->save();
             $log = \Neyko\Admin\Model\AdminLog::create(array("username" => \Neyko\Admin\Model\Administrator::find(\Session::get("admin"))->username, "message" => \Lang::get("admin::messages.createdadmin")));
             $log->save();
             return redirect('/admin')->with("message", \Lang::get("admin::messages.successcreateadmin"));
         } else {
             return redirect('/admin')->with("message", \Lang::get("admin::messages.adminexist"));
         }
     } else {
         return redirect('/admin')->with("message", \Lang::get("admin::messages.passwordsnotmatch"));
     }
 }
Esempio n. 2
0
 public function saveForm($module)
 {
     $module = \Neyko\Admin\Model\AdminModule::where("name", "=", $module)->first();
     $settings = \Config::get("admin." . $module->name);
     $model = $module->model;
     $form = $settings['form'];
     if (\Input::get("id")) {
         $item = $model::find(\Input::get("id"));
     } else {
         $item = new $model();
         $item->save();
     }
     foreach ($form['fields'] as $field) {
         if (in_array($field['type'], array('text', 'textarea', 'ckeditor', 'select', 'video', 'date'))) {
             $item->{$field}['name'] = \Input::get($field['name']);
         }
         if ($field['type'] == "switch") {
             $item->{$field}['name'] = \Input::get($field['name']) ? "1" : 0;
         }
         if ($field['type'] == 'picture') {
             $item->{$field}['name'] = \Input::get($field['name']);
             if (\Input::get($field['name'] . "-fresh")) {
                 $this->processPicture($field, $item, \Input::get($field['name']));
             }
         }
         if ($field['type'] == 'file') {
             $item->{$field}['name'] = \Input::get($field['name']);
             if (\Input::get($field['name'] . "-fresh")) {
                 $this->processFile($field, $item, \Input::get($field['name']));
             }
         }
         if ($field['type'] == 'admin') {
             if (\Input::get("admin_modules")) {
                 \Neyko\Admin\Model\AdminAccess::where("id_admin", "=", $item->id)->delete();
                 foreach (\Input::get("admin_modules") as $adminmodule) {
                     \Neyko\Admin\Model\AdminAccess::create(array("id_admin" => $item->id, "id_module" => $adminmodule));
                 }
             }
         }
         if ($field['type'] == 'checkbox') {
             $checked = $item->{$field}['options']['connector'];
             foreach ($checked as $check) {
                 $item->{$field}['options']['connector']()->detach($check->id);
             }
             foreach (\Input::get($field['name']) as $checkbox) {
                 $item->{$field}['options']['connector']()->attach($checkbox);
             }
         } else {
             if ($field['type'] == 'gallery' || $field['type'] == 'filegallery') {
                 $i = 0;
                 $c = 1;
                 $existing_ids = array();
                 $files = $item->{$field}['name'];
                 $count = (int) \Input::get($field['name'] . '-gcount');
                 while ($c <= $count) {
                     if (\Input::has($field['name'] . '-' . $i)) {
                         $name = \Input::get($field['name'] . '-' . $i);
                         $fresh = \Input::get($field['name'] . '-fresh-' . $i);
                         $position = \Input::get($field['name'] . '-position-' . $i);
                         if ($fresh) {
                             $object = new $field['class']();
                             if ($field['type'] == 'gallery') {
                                 $object->picture = $name;
                                 $this->processPicture($field, $item, \Input::get($field['name'] . '-' . $i));
                             } elseif ($field['type'] == 'filegallery') {
                                 $object->file = $name;
                                 $this->processFile($field, $item, \Input::get($field['name'] . '-' . $i));
                             }
                         } else {
                             $file_id = \Input::get($field['name'] . '-id-' . $i);
                             $existing_ids[] = $file_id;
                             $object = $field['class']::find($file_id);
                         }
                         if (isset($field['extrafields'])) {
                             foreach ($field['extrafields'] as $extraname => $extra) {
                                 if (isset($extra['lang'])) {
                                     foreach (\Config::get("admin/admin.langs") as $lang) {
                                         $e = \Input::get($field['name'] . '-extra-' . $extraname . '-' . $i . '_' . $lang);
                                         $object->translate($lang)->{$extraname} = $e;
                                     }
                                 } else {
                                     $e = \Input::get($field['name'] . '-extra-' . $extraname . '-' . $i);
                                     $property = ucfirst(preg_replace('/_/', '', $extraname));
                                     $object->{$property} = $e;
                                 }
                             }
                         }
                         $object->position = $position;
                         $object->{$field}['id_parent'] = $item->id;
                         $object->save();
                         $c++;
                     }
                     $i++;
                 }
                 foreach ($files as $file) {
                     if (!in_array($file->id, $existing_ids)) {
                         $file->delete();
                     }
                 }
             }
         }
     }
     $item->save();
     $main = $module->main;
     if (\Input::get("id")) {
         $log = \Neyko\Admin\Model\AdminLog::create(array("username" => \Neyko\Admin\Model\Administrator::find(\Session::get("admin"))->username, "message" => \Lang::get("admin::messages.updated") . $module->singular . " <b>" . $item->{$main} . "</b>"));
         $log->save();
     } else {
         $log = \Neyko\Admin\Model\AdminLog::create(array("username" => \Neyko\Admin\Model\Administrator::find(\Session::get("admin"))->username, "message" => \Lang::get("admin::messages.created") . $module->singular . " <b>" . $item->{$main} . "</b>"));
         $log->save();
     }
     if (\Input::get('submit') == 'update') {
         return redirect("/admin/" . $module->name . "/edit/" . $item->id)->with('message', \Lang::get("admin::messages.successfully_saved") . $module->singular . " <b>" . $item->{$main} . "</b>.");
     } else {
         return redirect("/admin/" . $module->name)->with('message', \Lang::get("admin::messages.successfully_saved") . $module->singular . " <b>" . $item[$module->main] . "</b>.");
     }
 }