Exemple #1
0
 /**
  * Update data of the asset
  *
  * @param mixed $data
  * @return void
  */
 function put($data)
 {
     $tmpFile = PIMCORE_WEBDAV_TEMP . "/" . md5($this->asset->getId() . microtime());
     file_put_contents($tmpFile, $data);
     $data = file_get_contents($tmpFile);
     unlink($tmpFile);
     $this->asset->setData($data);
     $this->asset->save();
 }
Exemple #2
0
 public function run()
 {
     // create default user asset
     $asset = Asset::where('filename', '=', 'default.png')->first();
     if ($asset == NULL) {
         $asset = new Asset();
         $asset->filename = 'default.png';
         $asset->path = 'assets/content/users';
         $asset->save();
     }
     $admin = Role::where('name', '=', 'Admin')->first();
     // create default roles
     if ($admin == NULL) {
         $admin = new Role();
         $admin->name = 'Admin';
         $admin->save();
     }
     $adminUser = User::where('username', '=', 'admin')->first();
     if ($adminUser != NULL) {
         echo "Admin User Already Exsit";
     } else {
         $adminUser = new User();
         $adminUser->username = '******';
         $adminUser->email = '*****@*****.**';
         $adminUser->password = '******';
         $adminUser->password_confirmation = 'admin';
         $adminUser->confirmation_code = md5(uniqid(mt_rand(), true));
         if ($adminUser->save()) {
             $adminUser->attachRole($admin);
             echo "Admin User Created";
         }
     }
 }
Exemple #3
0
 public function setupDatabases()
 {
     $name = $this->call('migrate', array('--path' => 'app/database/migrations/setup/'));
     $name = $this->call('migrate');
     // create the roles
     $roles = ['Admin', 'Writer', 'Reader'];
     foreach ($roles as $r) {
         $role = Role::whereName($r)->first();
         if ($role == null) {
             $role = new Role();
             $role->name = $r;
             $role->display_name = $r;
             $role->save();
             $this->info("{$role->id} Creating Role:{$r}");
         }
     }
     foreach (User::all() as $u) {
         $this->info("{$u->id} : user: {$u->username}");
     }
     // add core assets
     $m = Asset::findFromTag('missing-user-image');
     if ($m == NULL) {
         $m = new Asset();
         $m->path = "assets/content/uploads";
         $m->saveLocalFile(public_path('assets/content/common/missing/profile-default.png'), 'profile-default.png');
         $m->tag = 'missing-user-image';
         $m->shared = 1;
         $m->type = Asset::ASSET_TYPE_IMAGE;
         $m->save();
     }
     $this->comment("****\tAll Databases for Halp have been setup :-) \t****");
     return;
 }
Exemple #4
0
 function save()
 {
     $this->filter_access('Assets', 'roled_add', 'assets/index');
     $asset = new Asset();
     $asset->asset_name = $this->input->post('asset_name');
     $asset->asset_status = $this->input->post('asset_status');
     $asset->staff_id = $this->input->post('staff_id');
     $asset->date = $this->input->post('date');
     if ($asset->save()) {
         $this->session->set_flashdata('message', 'Asset successfully created!');
         redirect('assets/');
     } else {
         // Failed
         $asset->error_message('custom', 'Field required');
         $msg = $asset->error->custom;
         $this->session->set_flashdata('message', $msg);
         redirect('assets/add');
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY Import for ' . $filename . ' ====');
         $this->comment('============== NO DATA WILL BE WRITTEN ==============');
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $csv->setOffset(1);
     $duplicates = '';
     // Loop through the records
     $nbInsert = $csv->each(function ($row) use($duplicates) {
         $status_id = 1;
         if (is_numeric($row[0])) {
             $this->comment('User ' . $row[0] . ' is not a name - assume this user already exists');
         } elseif ($row[0] == '') {
             $this->comment('No user data provided - skipping user creation, just adding asset');
         } else {
             // Generate an email based on their name
             $name = explode(" ", $row[0]);
             $first_name = $name[0];
             $last_name = '';
             $email_last_name = '';
             if ($first_name == 'Unknown') {
                 $status_id = 7;
             }
             if (!array_key_exists(1, $name)) {
                 $last_name = '';
                 $email_last_name = $last_name;
                 $email_prefix = $first_name;
             } else {
                 // Loop through the rest of the explode so you don't truncate
                 for ($x = 0; $x < count($name); $x++) {
                     if ($x > 0 && $name[$x] != '') {
                         $last_name .= ' ' . $name[$x];
                         $email_last_name .= $name[$x];
                     }
                 }
                 $email_prefix = $first_name[0] . $email_last_name;
             }
             $email = strtolower(str_replace('.', '', $email_prefix)) . '@' . $this->option('domain');
             $email = str_replace("'", '', $email);
             $this->comment('Full Name: ' . $row[0]);
             $this->comment('First Name: ' . $first_name);
             $this->comment('Last Name: ' . $last_name);
             $this->comment('Email: ' . $email);
             $this->comment('Category Name: ' . $row[1]);
             $this->comment('Item: ' . $row[2]);
             $this->comment('Manufacturer ID: ' . $row[3]);
             $this->comment('Model No: ' . $row[4]);
             $this->comment('Serial No: ' . $row[5]);
             $this->comment('Asset Tag: ' . $row[6]);
             $this->comment('Location: ' . $row[7]);
         }
         $this->comment('------------- Action Summary ----------------');
         if (isset($email)) {
             if ($user = User::where('email', $email)->first()) {
                 $this->comment('User ' . $email . ' already exists');
             } else {
                 // Create the user
                 $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'Imported user'));
                 // Find the group using the group id
                 $userGroup = Sentry::findGroupById(3);
                 // Assign the group to the user
                 $user->addGroup($userGroup);
                 $this->comment('User ' . $first_name . ' created');
             }
         } else {
             $user = new User();
         }
         // Check for the location match and create it if it doesn't exist
         if ($location = Location::where('name', $row[7])->first()) {
             $this->comment('Location ' . $row[7] . ' already exists');
         } else {
             $location = new Location();
             $location->name = e($row[7]);
             $location->address = '';
             $location->city = '';
             $location->state = '';
             $location->country = '';
             $location->user_id = 1;
             if (!$this->option('testrun') == 'true') {
                 if ($location->save()) {
                     $this->comment('Location ' . $row[7] . ' was created');
                 } else {
                     $this->comment('Something went wrong! Location ' . $row[1] . ' was NOT created');
                 }
             } else {
                 $this->comment('Location ' . $row[7] . ' was (not) created - test run only');
             }
         }
         // Check for the category match and create it if it doesn't exist
         if ($category = Category::where('name', $row[1])->where('category_type', 'asset')->first()) {
             $this->comment('Category ' . $row[1] . ' already exists');
         } else {
             $category = new Category();
             $category->name = e($row[1]);
             $category->category_type = 'asset';
             $category->user_id = 1;
             if ($category->save()) {
                 $this->comment('Category ' . $row[1] . ' was created');
             } else {
                 $this->comment('Something went wrong! Category ' . $row[1] . ' was NOT created');
             }
         }
         // Check for the manufacturer match and create it if it doesn't exist
         if ($manufacturer = Manufacturer::where('name', $row[3])->first()) {
             $this->comment('Manufacturer ' . $row[3] . ' already exists');
         } else {
             $manufacturer = new Manufacturer();
             $manufacturer->name = e($row[3]);
             $manufacturer->user_id = 1;
             if ($manufacturer->save()) {
                 $this->comment('Manufacturer ' . $row[3] . ' was created');
             } else {
                 $this->comment('Something went wrong! Manufacturer ' . $row[3] . ' was NOT created');
             }
         }
         // Check for the asset model match and create it if it doesn't exist
         if ($asset_model = Model::where('name', $row[2])->where('modelno', $row[4])->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) {
             $this->comment('The Asset Model ' . $row[2] . ' with model number ' . $row[4] . ' already exists');
         } else {
             $asset_model = new Model();
             $asset_model->name = e($row[2]);
             $asset_model->manufacturer_id = $manufacturer->id;
             $asset_model->modelno = e($row[4]);
             $asset_model->category_id = $category->id;
             $asset_model->user_id = 1;
             if ($asset_model->save()) {
                 $this->comment('Asset Model ' . $row[2] . ' with model number ' . $row[4] . ' was created');
             } else {
                 $this->comment('Something went wrong! Asset Model ' . $row[2] . ' was NOT created');
             }
         }
         // Check for the asset match and create it if it doesn't exist
         $asset = new Asset();
         $asset->name = e($row[2]);
         $asset->serial = e($row[5]);
         $asset->asset_tag = e($row[6]);
         $asset->model_id = $asset_model->id;
         $asset->assigned_to = $user->id;
         $asset->rtd_location_id = $location->id;
         $asset->user_id = 1;
         $asset->status_id = $status_id;
         if ($asset->save()) {
             $this->comment('Asset ' . $row[2] . ' with serial number ' . $row[5] . ' was created');
         } else {
             $this->comment('Something went wrong! Asset ' . $row[5] . ' was NOT created');
         }
         $this->comment('=====================================');
         return true;
     });
 }
Exemple #6
0
 /**
  * @return void
  */
 function setName($name)
 {
     $this->asset->setFilename(Pimcore_File::getValidFilename($name));
     $this->asset->save();
 }
Exemple #7
0
 public function approve()
 {
     //check the users group
     $authorizers = Sentry::findGroupByName('Authorizers');
     $admins = Sentry::findGroupByName('Admin');
     //DLN authorizers
     if (Sentry::getUser()->inGroup($authorizers)) {
         $this->request_code = 1;
         $this->save();
         return array('success' => 1, 'message' => 'Request Approved', 'type' => $this->type);
     } elseif (Sentry::getUser()->inGroup($admins)) {
         //get all license types for request
         $lcnsNames = $this->licenseTypes()->lists('name');
         //get available license seats for each license type
         $that = $this;
         $toAdd = [];
         if ($this->type == 'license') {
             //TODO:: remove and place in seperate method - this will need to be used to update a request
             foreach ($lcnsNames as $lcnsName) {
                 $lcnsSeat = DB::table('licenses')->join('license_types', 'licenses.type_id', '=', 'license_types.id')->join('license_seats', 'licenses.id', '=', 'license_seats.license_id')->orwhere(function ($query) use($lcnsName, $that) {
                     $query->where('license_types.name', '=', $lcnsName)->where('licenses.role_id', $that->role_id)->whereNull('license_seats.assigned_to');
                 })->first();
                 //if seats available add it to array for later processing, else return with error message
                 if ($lcnsSeat) {
                     $toAdd[$lcnsName] = $lcnsSeat;
                 } else {
                     $messageKey = str_replace(' ', '', strtolower($lcnsName));
                     $error = Lang::get('request.message_no_lcns.' . $lcnsName);
                     return array('success' => 0, 'message' => $error);
                 }
             }
             foreach ($toAdd as $key => $lcnsSeat) {
                 if ($key == 'SABA Publisher') {
                     //create computer name as an asset if it doesnt exist
                     if ($obj = DB::table('assets')->where('serial', $this->pc_name)->first(array('id'))) {
                         $asset = Asset::find($obj->id);
                     } else {
                         $asset = new Asset();
                         $asset->name = "DWAN PC";
                         $asset->serial = $this->pc_name;
                         $asset->asset_tag = $this->pc_name;
                         $asset->model_id = 7;
                         //TODO: Remove this hard coding for model id
                         $asset->status_id = 1;
                         $asset->assigned_to = $this->account->id;
                     }
                     $asset->role_id = $this->role_id;
                     $asset->save();
                     License::checkOutToAsset($lcnsSeat->id, $asset->id);
                 }
                 //checkout to account the request has been made for
                 License::checkOutToAccount($lcnsSeat->id, $this->account_id);
             }
         } elseif ($this->type == 'checkin') {
             //clear license fields
             $seat = LicenseSeat::find($this->license_id);
             $seat->checkIn();
         }
         //detach requested licenses
         $this->licenseTypes()->detach();
         $type = $this->type;
         //marked as closed
         $this->delete();
         return array('success' => 1, 'message' => 'Request Approved', 'type' => $type);
     }
 }
 public static function saveGoogleProfileImage(&$google_user, &$user)
 {
     // profile image
     //if(property_exists($google_user, 'picture')) {
     $image_url = $google_user->picture;
     if ($image_url) {
         $image_url_parts = explode('?', $image_url);
         $image_url = $image_url_parts[0];
         $id = $user->id;
         $image_name = $user->username . '_' . $id . '.jpg';
         if ($user->profileImage && $user->profileImage->isShared() != true) {
             $user->profileImage->removeOldFile();
             $user->profileImage->saveRemoteAsset($image_url, $image_name, ASSET::ASSET_TYPE_IMAGE);
             $user->profileImage->user()->associate($user);
         } else {
             $userImage = new Asset();
             $userImage->path = 'assets/content/users';
             $userImage->saveRemoteAsset($image_url, $image_name, ASSET::ASSET_TYPE_IMAGE);
             $userImage->save();
             $user->profileImage()->save($userImage);
             $user->profileImage->user()->associate($user);
         }
     }
     //}
 }
Exemple #9
0
 public function makeDefaultProfileImage()
 {
     $userImage = $this->profileImage()->first();
     if ($userImage == null) {
         $userImage = new Asset();
     }
     $userImage->path = 'assets/content/users';
     $userImage->saveRemoteImage('assets/content/common/porfile-default.png', $this->username . '_' . $this->id . '.png');
     $userImage->user()->associate($this);
     $userImage->save();
     $this->profileImage()->save($userImage);
 }
Exemple #10
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY Import for ' . $filename . ' ====');
         $this->comment('============== NO DATA WILL BE WRITTEN ==============');
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $csv->setOffset(1);
     $duplicates = '';
     // Loop through the records
     $nbInsert = $csv->each(function ($row) use($duplicates) {
         $status_id = 1;
         // Let's just map some of these entries to more user friendly words
         if (array_key_exists('0', $row)) {
             $user_name = $row[0];
         } else {
             $user_name = '';
         }
         if (array_key_exists('1', $row)) {
             $user_email = $row[1];
         } else {
             $user_email = '';
         }
         if (array_key_exists('2', $row)) {
             $user_asset_category = $row[2];
         } else {
             $user_asset_category = '';
         }
         if (array_key_exists('3', $row)) {
             $user_asset_name = $row[3];
         } else {
             $user_asset_name = '';
         }
         if (array_key_exists('4', $row)) {
             $user_asset_mfgr = $row[4];
         } else {
             $user_asset_mfgr = '';
         }
         if (array_key_exists('5', $row)) {
             $user_asset_modelno = $row[5];
         } else {
             $user_asset_modelno = '';
         }
         if (array_key_exists('6', $row)) {
             $user_asset_serial = $row[6];
         } else {
             $user_asset_serial = '';
         }
         if (array_key_exists('7', $row)) {
             $user_asset_tag = $row[7];
         } else {
             $user_asset_tag = '';
         }
         if (array_key_exists('8', $row)) {
             $user_asset_location = $row[8];
         } else {
             $user_asset_location = '';
         }
         if (array_key_exists('9', $row)) {
             $user_asset_notes = $row[9];
         } else {
             $user_asset_notes = '';
         }
         if (array_key_exists('10', $row)) {
             if ($row[10] != '') {
                 $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[10]));
             } else {
                 $user_asset_purchase_date = '';
             }
         } else {
             $user_asset_purchase_date = '';
         }
         // A number was given instead of a name
         if (is_numeric($user_name)) {
             $this->comment('User ' . $user_name . ' is not a name - assume this user already exists');
             // No name was given
         } elseif ($user_name == '') {
             $this->comment('No user data provided - skipping user creation, just adding asset');
             $first_name = '';
             $last_name = '';
         } else {
             $name = explode(" ", $user_name);
             $first_name = $name[0];
             $email_last_name = '';
             if (!array_key_exists(1, $name)) {
                 $last_name = '';
                 $email_last_name = $last_name;
                 $email_prefix = $first_name;
             } else {
                 $last_name = str_replace($first_name, '', $user_name);
                 if ($this->option('email_format') == 'filastname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name[0] . $email_last_name;
                 } elseif ($this->option('email_format') == 'firstname.lastname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name . '.' . $email_last_name;
                 } elseif ($this->option('email_format') == 'firstname') {
                     $email_last_name .= str_replace(' ', '', $last_name);
                     $email_prefix = $first_name;
                 }
             }
             // Generate an email based on their name if no email address is given
             if ($user_email == '') {
                 if ($first_name == 'Unknown') {
                     $status_id = 7;
                 }
                 $email = strtolower($email_prefix) . '@' . $this->option('domain');
                 $user_email = str_replace("'", '', $email);
             }
         }
         $this->comment('Full Name: ' . $user_name);
         $this->comment('First Name: ' . $first_name);
         $this->comment('Last Name: ' . $last_name);
         $this->comment('Email: ' . $user_email);
         $this->comment('Category Name: ' . $user_asset_category);
         $this->comment('Item: ' . $user_asset_name);
         $this->comment('Manufacturer ID: ' . $user_asset_mfgr);
         $this->comment('Model No: ' . $user_asset_modelno);
         $this->comment('Serial No: ' . $user_asset_serial);
         $this->comment('Asset Tag: ' . $user_asset_tag);
         $this->comment('Location: ' . $user_asset_location);
         $this->comment('Purchase Date: ' . $user_asset_purchase_date);
         $this->comment('Notes: ' . $user_asset_notes);
         $this->comment('------------- Action Summary ----------------');
         if ($user_email != '') {
             if ($user = User::where('email', $user_email)->first()) {
                 $this->comment('User ' . $user_email . ' already exists');
             } else {
                 // Create the user
                 $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'Imported user'));
                 // Find the group using the group id
                 $userGroup = Sentry::findGroupById(3);
                 // Assign the group to the user
                 $user->addGroup($userGroup);
                 $this->comment('User ' . $first_name . ' created');
             }
         } else {
             $user = new User();
         }
         // Check for the location match and create it if it doesn't exist
         if ($location = Location::where('name', $user_asset_location)->first()) {
             $this->comment('Location ' . $user_asset_location . ' already exists');
         } else {
             $location = new Location();
             $location->name = e($user_asset_location);
             $location->address = '';
             $location->city = '';
             $location->state = '';
             $location->country = '';
             $location->user_id = 1;
             if (!$this->option('testrun') == 'true') {
                 if ($location->save()) {
                     $this->comment('Location ' . $user_asset_location . ' was created');
                 } else {
                     $this->comment('Something went wrong! Location ' . $user_asset_location . ' was NOT created');
                 }
             } else {
                 $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only');
             }
         }
         // Check for the category match and create it if it doesn't exist
         if ($category = Category::where('name', $user_asset_category)->where('category_type', 'asset')->first()) {
             $this->comment('Category ' . $user_asset_category . ' already exists');
         } else {
             $category = new Category();
             $category->name = e($user_asset_category);
             $category->category_type = 'asset';
             $category->user_id = 1;
             if ($category->save()) {
                 $this->comment('Category ' . $user_asset_category . ' was created');
             } else {
                 $this->comment('Something went wrong! Category ' . $user_asset_category . ' was NOT created');
             }
         }
         // Check for the manufacturer match and create it if it doesn't exist
         if ($manufacturer = Manufacturer::where('name', $user_asset_mfgr)->first()) {
             $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists');
         } else {
             $manufacturer = new Manufacturer();
             $manufacturer->name = e($user_asset_mfgr);
             $manufacturer->user_id = 1;
             if ($manufacturer->save()) {
                 $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created');
             } else {
                 $this->comment('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created');
             }
         }
         // Check for the asset model match and create it if it doesn't exist
         if ($asset_model = Model::where('name', $user_asset_name)->where('modelno', $user_asset_modelno)->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) {
             $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists');
         } else {
             $asset_model = new Model();
             $asset_model->name = e($user_asset_name);
             $asset_model->manufacturer_id = $manufacturer->id;
             $asset_model->modelno = e($user_asset_modelno);
             $asset_model->category_id = $category->id;
             $asset_model->user_id = 1;
             if ($asset_model->save()) {
                 $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created');
             } else {
                 $this->comment('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created');
             }
         }
         // Check for the asset match and create it if it doesn't exist
         $asset = new Asset();
         $asset->name = e($user_asset_name);
         $asset->serial = e($user_asset_serial);
         $asset->asset_tag = e($user_asset_tag);
         $asset->model_id = $asset_model->id;
         $asset->assigned_to = $user->id;
         $asset->rtd_location_id = $location->id;
         $asset->user_id = 1;
         $asset->status_id = $status_id;
         if ($user_asset_purchase_date != '') {
             $asset->purchase_date = $user_asset_purchase_date;
         } else {
             $asset->purchase_date = NULL;
         }
         $asset->notes = e($user_asset_notes);
         if ($asset->save()) {
             $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created');
         } else {
             $this->comment('Something went wrong! Asset ' . $user_asset_name . ' was NOT created');
         }
         $this->comment('=====================================');
         return true;
     });
 }
 public function register()
 {
     $wantsJson = Request::wantsJson();
     $creds = GoogleSessionController::getCreds();
     $client = GoogleSessionController::getClient();
     $code = Input::get('code');
     if ($code) {
         // Exchange the OAuth 2.0 authorization code for user credentials.
         $client->authenticate($code);
         $token = json_decode($client->getAccessToken());
         $attributes = $client->verifyIdToken($token->id_token, $creds->client_id)->getAttributes();
         $oauth2 = new Google_Service_Oauth2($client);
         $google_user = $oauth2->userinfo->get();
         $email = $google_user->email;
         $username = explode("@", $email)[0];
         // return Response::json(['errors'=>$user->givenName]);
         if ($google_user->hd != 'ideo.com') {
             $errors = ['errors' => [Config::get('config.site_name') . ' is for IDEO only']];
             return $wantsJson ? Response::json($errors) : Redirect::to('register')->with($errors);
         }
         $user = new User();
         $user->username = $username;
         $user->email = $email;
         $password = Hash::make($username);
         // <-- temp...
         $user->firstname = $google_user->givenName;
         $user->lastname = $google_user->familyName;
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->google_token = json_encode($token);
         if ($user->save()) {
             // profile image
             $image_url = $google_user->picture;
             if ($image_url) {
                 $image_url_parts = explode('?', $image_url);
                 $image_url = $image_url_parts[0];
                 $id = $user->id;
                 $image_name = $username . '_' . $id . '.jpg';
                 $save_path = 'assets/content/users';
                 $userImage = new Asset();
                 $userImage->saveRemoteImage($image_url, $save_path, $image_name);
                 $userImage->save();
                 $user->profileImage()->save($userImage);
             }
             // Roles
             if ($username == 'tvanderlin') {
                 $adminRole = Role::where('name', '=', 'Admin')->first();
                 $user->attachRole($adminRole);
             } else {
                 $role = $role = Role::where('name', '=', 'Writer')->first();
                 if ($role) {
                     $user->attachRole($role);
                     $user->save();
                 }
             }
             $back_url = 'users/' . $username;
             Auth::login($user);
             return Redirect::to($back_url);
         } else {
             return $wantsJson ? Response::json(['errors' => $user->errors()->all()]) : Redirect::to('register')->with(['errors' => $user->errors()->all()]);
         }
         return Response::json(['data' => $token, 'attr' => $attributes, 'user' => $user]);
     }
     return $wantsJson ? Response::json(['errors' => ['Missing OAuth Code']]) : Redirect::to('register')->with(['errors' => $user->errors()->all()]);
 }
Exemple #12
0
 public function seedUsers()
 {
     $user_photos = File::files($this->seed_path);
     Asset::setFromSeed(true);
     foreach (User::all() as $user) {
         $user->delete();
     }
     $faker = Faker\Factory::create();
     $seeder = new LOFaker();
     $n = 50;
     // also creat admin users (kim & I)
     $admins = array(['username' => 'tvanderlin', 'firstname' => 'Todd', 'lastname' => 'Vanderlin', 'email' => '*****@*****.**'], ['username' => 'kmiller', 'firstname' => 'Kim', 'lastname' => 'Miller', 'email' => '*****@*****.**']);
     foreach ($admins as $data) {
         $data = (object) $data;
         $user = new User();
         $user->timestamps = false;
         $user->email = $data->email;
         $user->username = $data->username;
         $user->firstname = $data->firstname;
         $user->lastname = $data->lastname;
         $password = Hash::make($user->username);
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmed = 1;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->created_at = $user->updated_at = $faker->dateTimeBetween('-3 years', 'now');
         $user->save();
         $role = Role::where('name', '=', 'Admin')->first();
         $user->save();
         $user->attachRole($role);
         $user->save();
         $this->info('Creating *** Admin *** User: '******'men', 'women']);
         $photo = array_random_item($user_photos);
         $role = Role::where('name', '=', 'Writer')->first();
         $joinDate = $faker->dateTimeBetween('-3 years', 'now');
         $user = new User();
         $user->timestamps = false;
         $user->email = 'fake_' . $faker->unique()->email;
         $user->firstname = $faker->firstname;
         $user->lastname = $faker->lastname;
         $user->username = preg_replace("/[^A-Za-z0-9 ]/", '', $faker->unique()->userName);
         $password = Hash::make($faker->password);
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmed = 1;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->created_at = $user->updated_at = $joinDate;
         if ($user->save() == false) {
             $this->error($user->errors() . " " . $user->username);
         }
         $userImage = new Asset();
         $userImage->path = 'assets/content/users';
         $userImage->saveLocalFile($photo, $user->username . ".jpg", Asset::ASSET_TYPE_IMAGE);
         $userImage->save();
         $user->profileImage()->save($userImage);
         $user->profileImage->user()->associate($user);
         $user->save();
         $user->attachRole($role);
         $user->save();
         $this->info($user->id . ' Creating User: ' . $user->getName() . " [{$user->username}, {$user->email}]");
     }
     foreach (User::all() as $user) {
         Notification::fire($user, Notification::NOTIFICATION_HALP_WELCOME);
     }
 }
Exemple #13
0
 public function createFakeUser()
 {
     $random_user_data = (object) json_decode(get_remote_file('http://api.randomuser.me/'));
     $random_user_data = $random_user_data->results[0]->user;
     $faker = Faker\Factory::create();
     $role = $role = Role::where('name', '=', 'Writer')->first();
     $joinDate = $faker->dateTimeBetween('-3 years', 'now');
     $user = new User();
     $user->timestamps = false;
     $user->username = $random_user_data->username;
     $user->email = $random_user_data->email;
     $password = Hash::make($random_user_data->username);
     $user->firstname = $random_user_data->name->first;
     $user->lastname = $random_user_data->name->last;
     $user->password = $password;
     $user->password_confirmation = $password;
     $user->confirmed = 1;
     $user->confirmation_code = md5($user->username . time('U'));
     $user->created_at = $user->updated_at = $joinDate;
     $user->save();
     $image_url = $random_user_data->picture->large;
     $userImage = new Asset();
     $userImage->path = 'assets/content/users';
     $userImage->saveRemoteAsset($image_url, $user->username . ".jpg", Asset::ASSET_TYPE_IMAGE);
     $userImage->save();
     $user->profileImage()->save($userImage);
     $user->profileImage->user()->associate($user);
     $user->save();
     $user->attachRole($role);
     $user->save();
     return $user;
 }
 private function processImport($file, $assetClass)
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         if (!in_array($file->getClientOriginalExtension(), array("xls", "xlsx", "csv"))) {
             Input::flash();
             return Redirect::to('assets/network/import')->with('message', "Invalid file selected.");
         } else {
             $filename = "upload-" . str_random(9) . "." . $file->getClientOriginalExtension();
             $file->move("uploads", $filename);
             $readFile = "uploads/" . $filename;
             $reader = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) {
             })->get();
             /*
              * 				Before validating each rows of the file uploaded, the file itself is checked if it has the valid attributes (columns)
              * 				using the algorithm found below.
              *
              * 				1. File is read.
              * 				2. Boolean variable $excelIsValid to check if the file is valid. Set to false by default.
              *
              */
             $excelChecker = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) {
             })->get()->toArray();
             $excelIsValid = false;
             /*
              * 				3. Loop through the excel file and check if at least once all the columns have been present.
              * 				4. If it does, $excelIsValid is set to true.
              * 				5. If $excelIsValid is still false by end of the loop, it is automatically assumed that the file is:
              * 					A.) Empty
              * 					B.) Does not have the right attributes.
              * 					C.) Has valid columns, but does not have any valid entry.
              *
              */
             foreach ($excelChecker as $ex) {
                 if (isset($ex["assettag"]) && isset($ex["serialnumber"]) && isset($ex["status"])) {
                     $excelIsValid = true;
                 }
             }
             /*				6. If file is invalid, redirect to import form and return an error. */
             if (!$excelIsValid) {
                 Input::flash();
                 File::delete($readFile);
                 return Redirect::to('assets/network/import')->with('message', "Excel file has invalid attributes. Please download the form.");
             }
             /*
              * 				CHECKING EXCEL FILE FOR ERRORS WHILE READING THE ROWS
              *
              * 				1. $hasError is a Boolean variable that is simply used to tell if any error has been found.
              * 					This variable is, by default, set to false. If any error has been detected, it is set to true,
              * 					regardless of how many errors has been detected.
              *
              * 				2. $rowIndex indexes which row the reader is currently reading. Default value set to 1 because
              * 					the first row of excel files is automatically set as the attribute row. When the reader reads each row,
              * 					$rowIndex is incremented. For example, reader is currently reading row 2, $rowIndex will then be incremented,
              * 					setting its value to 2, thus the row number.
              *
              * 				3. $rowsWithErrors is the array of the rows with errors. To explain further, let's say excel file has 10 readable (non-attrib)
              * 					rows. No errors were found from rows number 2-8, but errors were found in rows 9, 10, and 11. These 9, 10, and 11
              * 					will then be in the $rowsWithError.
              *
              * 				4. $error array is the variable that will be used to collect all errors found from the excel file.
              * 					This is a two-dimensional array.
              *
              *
              */
             $hasError = false;
             //Detects if there are any errors.
             $hasCorrectRows = false;
             $rowIndex = 1;
             //Indexes which row the reader is reading.
             $rowsWithErrors = array();
             //This is used to contain in an array the row numbers of the rows with error.
             $error = array();
             //Error details collector.
             foreach ($reader as $r) {
                 /*
                  * 				5. Here, we immediately increment the value of $rowIndex, since the variable will be used in the core logic of this method.
                  *
                  * 				6. $errorCount variable is a variable used in every loop. Set to 0 when the loop begins, so it always comes back to 0 for every loop.
                  * 					$errorCount is used to track the number of errors for the current row. This variable goes hand in hand with the
                  * 					$rowsWithError array when publishing the rows with errors, and the error details for each row with error.
                  *
                  * 					This is how $rowsWithError and $rowCount will be used:
                  *
                  * 					for each $rowWithErrors:
                  * 						Row $rowWithErrors Index:
                  * 							Errors Found :
                  * 							$rowCount 1. Foo bar
                  * 							$rowCount 2. Jane Doe etc..
                  *
                  *
                  */
                 $rowIndex += 1;
                 $errorCount = 0;
                 //Counts the number of errors for the currect row.
                 $rowHasError = false;
                 //Check if this row has error. I will use this before the reading of the row ends.
                 //					If $rowHasError is still false by end of the reading, then I will write it in the database.
                 /*"CP"=>"CP",
                 			"Dual Boot"=>"Dual Boot",
                 		"Nokia"=>"Nokia",
                 		"NWL"=>"NWL",
                 		"OAM"=>"OAM",
                 		"Recruitment"=>"Recruitment",
                 		"Ubuntu"=>"Ubuntu"
                 		*
                 		*/
                 $warranty_start = !empty(trim($r->warrantystart)) ? trim($r->warrantystart) : "1994-04-16";
                 $validator = Validator::make(array("asset tag" => trim($r->assettag), "serial number" => trim($r->serialnumber), "model" => trim($r->modelid), "employee number" => trim($r->employeenumber), "status" => trim($r->status), "warranty start date" => trim($r->warrantystart), "warranty end date" => trim($r->warrantyend)), array("asset tag" => "required|unique:tbl_assets,asset_tag", "serial number" => "required|unique:tbl_assets,serial_number", "model" => "exists:tbl_asset_models,id", "employee number" => "numeric|exists:tbl_employees,employee_number", "status" => "required|in:Available,For Repair,Installed,Lost,Retired", "warranty start date" => "required_with:warranty end date|date:Y-m-d", "warranty end date" => "date:Y-m-d|after:" . $warranty_start), array("after" => "The :attribute must be after the warranty start date."));
                 if ($validator->fails()) {
                     /* 					7. When error has been found, $rowsWithError is immediately updated. Also, $hasError and $rowHasError are set to true.*/
                     $hasError = true;
                     $rowHasError = true;
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     /* 					8. Then I will check which fields have errors.
                      *
                      *					9. If an error has been found in a certain field,
                      *					   I will loop through the errors found on that field, increment the $errorCount (which, again, tracks
                      *					   how many errors has been found on a certain row.), update the two-dimensional $error array.
                      *					   Please note that the first array of $error contains the row number which the errors found belong to.
                      *
                      */
                     if ($validator->messages()->get("asset tag")) {
                         foreach ($validator->messages()->get("asset tag") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("serial number")) {
                         foreach ($validator->messages()->get("serial number") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("model")) {
                         foreach ($validator->messages()->get("model") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("employee number")) {
                         foreach ($validator->messages()->get("employee number") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("status")) {
                         foreach ($validator->messages()->get("status") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("warranty start date")) {
                         foreach ($validator->messages()->get("warranty start date") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("warranty end date")) {
                         foreach ($validator->messages()->get("warranty end date") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                 }
                 if ($r->status != "Lost" && Employee::where("employee_number", "=", $r->employeenumber)->whereIn("status", array("OJT Graduate", "Graduate", "Resigned", "Obsolete"))->first()) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Cannot assign an asset to employees no longer working in the company." . "<br/>";
                 }
                 if ($r->modelid != null && !Model::where("classification_id", "=", $assetClass)->where("id", "=", $r->modelid)->first()) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "The asset model does not belong to the selected asset type." . "<br/>";
                 }
                 if (!$rowHasError) {
                     $hasCorrectRows = true;
                     //To set image as null if asset class is not laptop.
                     $image = !AssetClassification::where("id", "=", $assetClass)->where("name", "=", "Laptops")->first() ? null : $r->image;
                     //Add the new asset
                     $asset = new Asset();
                     $asset->asset_tag = trim($r->assettag);
                     $asset->serial_number = trim($r->serialnumber) != null ? trim($r->serialnumber) : null;
                     $asset->model_id = $r->modelid != null ? $r->modelid : null;
                     $asset->location = $r->location != null ? $r->location : null;
                     $asset->employee_number = $r->employeenumber != null ? trim($r->employeenumber) : null;
                     $asset->warranty_start = trim($r->warrantystart) != null ? trim($r->warrantystart) : null;
                     $asset->warranty_end = trim($r->warrantyend) != null ? $r->warrantyend : null;
                     $asset->classification_id = $assetClass;
                     $asset->status = trim($r->status);
                     $asset->notes = trim($r->notes) != null ? trim($r->notes) : null;
                     $asset->date_added = date("Y-m-d H:i:s");
                     $asset->save();
                     //Log the new asset to asset logs
                     if (!empty(trim($r->employeenumber))) {
                         $employee = Employee::where("employee_number", "=", $r->employeenumber)->first();
                         $desc = "Network Asset <strong>" . $asset->asset_tag . ",</strong> SN: <strong>" . $asset->serial_number . "</strong> added to the database and assigned to employee <strong>" . $employee->first_name . " " . $employee->last_name . "</strong> with asset status <strong>" . $asset->status . "</strong>.";
                     } else {
                         $desc = "Network Asset <strong>" . $asset->asset_tag . "</strong>, SN: <strong>" . $asset->serial_number . "</strong> added to the database with status <strong>" . $asset->status . "</strong>.";
                     }
                     $assetLog = new AssetLog();
                     $assetLog->user_id = Session::get("user_id");
                     $assetLog->asset_id = $asset->id;
                     $assetLog->employee_id = !empty($asset->employee->id) ? $asset->employee->id : null;
                     $assetLog->description = $desc;
                     $assetLog->transaction = "History";
                     $assetLog->save();
                     //Parallel logging to system logs
                     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> added network asset <strong>" . $asset->asset_tag . "</strong>, SN: <strong>" . $asset->serial_number . "</strong> ";
                     $newLog = new UserLog();
                     $newLog->description = $desc;
                     $newLog->user_id = Session::get('user_id');
                     $newLog->type = "System";
                     $newLog->save();
                 }
             }
             File::delete($readFile);
             if ($hasCorrectRows) {
                 //Log the changes made
                 $desc = "(" . Session::get("user_type") . ") <b>" . Session::get("username") . "</b> has imported data to network assets database. ";
                 $newLog = new UserLog();
                 $newLog->description = $desc;
                 $newLog->user_id = Session::get('user_id');
                 $newLog->save();
             }
             return $this->importResult($hasError, $hasCorrectRows, $rowsWithErrors, $error);
         }
     } else {
         return Redirect::to('/');
     }
 }
 /**
  * update_images()
  * Updates the image details for an entire image set (thumbnail, small, image) */
 function update_images($images)
 {
     if (!is_array($images)) {
         return false;
     }
     $db = DB::get();
     $table = DatabaseObject::tablename(Asset::$table);
     foreach ($images as $i => $img) {
         $query = "SELECT imgs.id FROM {$table} AS thumb LEFT JOIN {$table} AS imgs ON thumb.src=imgs.src OR thumb.src=imgs.id WHERE thumb.id={$img['id']}";
         $imageset = $db->query($query);
         foreach ($imageset as $is) {
             $Image = new Asset();
             unset($Image->_datatypes['data'], $Image->data);
             $Image->load($is->id);
             $Image->properties['title'] = $img['title'];
             $Image->properties['alt'] = $img['alt'];
             $Image->save();
         }
     }
     return true;
 }
 function save_category($Category)
 {
     global $Shopp;
     $db = DB::get();
     check_admin_referer('shopp-save-category');
     if (!current_user_can(SHOPP_USERLEVEL)) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $this->settings_save();
     // Save workflow setting
     $Shopp->Catalog = new Catalog();
     $Shopp->Catalog->load_categories(array('where' => 'true'));
     if (!isset($_POST['slug']) && empty($Category->slug)) {
         $Category->slug = sanitize_title_with_dashes($_POST['name']);
     }
     if (isset($_POST['slug'])) {
         unset($_POST['slug']);
     }
     // Work out pathing
     $paths = array();
     if (!empty($Category->slug)) {
         $paths = array($Category->slug);
     }
     // Include self
     $parentkey = -1;
     // If we're saving a new category, lookup the parent
     if ($_POST['parent'] > 0) {
         array_unshift($paths, $Shopp->Catalog->categories[$_POST['parent']]->slug);
         $parentkey = $Shopp->Catalog->categories[$_POST['parent']]->parent;
     }
     while ($category_tree = $Shopp->Catalog->categories[$parentkey]) {
         array_unshift($paths, $category_tree->slug);
         $parentkey = $category_tree->parent;
     }
     if (count($paths) > 1) {
         $_POST['uri'] = join("/", $paths);
     } else {
         $_POST['uri'] = $paths[0];
     }
     if (!empty($_POST['deleteImages'])) {
         $deletes = array();
         if (strpos($_POST['deleteImages'], ",")) {
             $deletes = explode(',', $_POST['deleteImages']);
         } else {
             $deletes = array($_POST['deleteImages']);
         }
         $Category->delete_images($deletes);
     }
     if (!empty($_POST['images']) && is_array($_POST['images'])) {
         $Category->link_images($_POST['images']);
         $Category->save_imageorder($_POST['images']);
         if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) {
             foreach ($_POST['imagedetails'] as $i => $data) {
                 $Image = new Asset();
                 unset($Image->_datatypes['data'], $Image->data);
                 $Image->load($data['id']);
                 $Image->properties['title'] = $data['title'];
                 $Image->properties['alt'] = $data['alt'];
                 $Image->save();
             }
         }
     }
     // Variation price templates
     if (!empty($_POST['price']) && is_array($_POST['price'])) {
         foreach ($_POST['price'] as &$pricing) {
             $pricing['price'] = floatvalue($pricing['price']);
             $pricing['saleprice'] = floatvalue($pricing['saleprice']);
             $pricing['shipfee'] = floatvalue($pricing['shipfee']);
         }
         $Category->prices = stripslashes_deep($_POST['price']);
     } else {
         $Category->prices = array();
     }
     if (empty($_POST['specs'])) {
         $Category->specs = array();
     } else {
         $_POST['specs'] = stripslashes_deep($_POST['specs']);
     }
     if (empty($_POST['options']) || count($_POST['options']) == 1 && !isset($_POST['options'][1]['options'])) {
         $_POST['options'] = $Category->options = array();
         $_POST['prices'] = $Category->prices = array();
     } else {
         $_POST['options'] = stripslashes_deep($_POST['options']);
     }
     if (isset($_POST['content'])) {
         $_POST['description'] = $_POST['content'];
     }
     $Category->updates($_POST);
     $Category->save();
     do_action_ref_array('shopp_category_saved', array(&$Category));
     $updated = '<strong>' . $Category->name . '</strong> ' . __('category saved.', 'Shopp');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     if (!$this->option('testrun') == 'true') {
         $this->comment('======= Importing Assets from ' . $filename . ' =========');
     } else {
         $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ====');
         $this->comment('============== NO DATA WILL BE WRITTEN ==============');
     }
     if (!ini_get("auto_detect_line_endings")) {
         ini_set("auto_detect_line_endings", '1');
     }
     $csv = Reader::createFromPath($this->argument('filename'));
     $csv->setNewline("\r\n");
     $csv->setOffset(1);
     $duplicates = '';
     // Loop through the records
     $nbInsert = $csv->each(function ($row) use($duplicates) {
         $status_id = 1;
         // Let's just map some of these entries to more user friendly words
         // User's name
         if (array_key_exists('0', $row)) {
             $user_name = trim($row[0]);
         } else {
             $user_name = '';
         }
         // User's email
         if (array_key_exists('1', $row)) {
             $user_email = trim($row[1]);
         } else {
             $user_email = '';
         }
         // User's email
         if (array_key_exists('2', $row)) {
             $user_username = trim($row[2]);
         } else {
             $user_username = '';
         }
         // Asset Name
         if (array_key_exists('3', $row)) {
             $user_asset_asset_name = trim($row[3]);
         } else {
             $user_asset_asset_name = '';
         }
         // Asset Category
         if (array_key_exists('4', $row)) {
             $user_asset_category = trim($row[4]);
         } else {
             $user_asset_category = '';
         }
         // Asset Name
         if (array_key_exists('5', $row)) {
             $user_asset_name = trim($row[5]);
         } else {
             $user_asset_name = '';
         }
         // Asset Manufacturer
         if (array_key_exists('6', $row)) {
             $user_asset_mfgr = trim($row[6]);
         } else {
             $user_asset_mfgr = '';
         }
         // Asset model number
         if (array_key_exists('7', $row)) {
             $user_asset_modelno = trim($row[7]);
         } else {
             $user_asset_modelno = '';
         }
         // Asset serial number
         if (array_key_exists('8', $row)) {
             $user_asset_serial = trim($row[8]);
         } else {
             $user_asset_serial = '';
         }
         // Asset tag
         if (array_key_exists('9', $row)) {
             $user_asset_tag = trim($row[9]);
         } else {
             $user_asset_tag = '';
         }
         // Asset location
         if (array_key_exists('10', $row)) {
             $user_asset_location = trim($row[10]);
         } else {
             $user_asset_location = '';
         }
         // Asset notes
         if (array_key_exists('11', $row)) {
             $user_asset_notes = trim($row[11]);
         } else {
             $user_asset_notes = '';
         }
         // Asset purchase date
         if (array_key_exists('12', $row)) {
             if ($row[12] != '') {
                 $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12]));
             } else {
                 $user_asset_purchase_date = '';
             }
         } else {
             $user_asset_purchase_date = '';
         }
         // Asset purchase cost
         if (array_key_exists('13', $row)) {
             if ($row[13] != '') {
                 $user_asset_purchase_cost = trim($row[13]);
             } else {
                 $user_asset_purchase_cost = '';
             }
         } else {
             $user_asset_purchase_cost = '';
         }
         // Asset Company Name
         if (array_key_exists('14', $row)) {
             if ($row[14] != '') {
                 $user_asset_company_name = trim($row[14]);
             } else {
                 $user_asset_company_name = '';
             }
         } else {
             $user_asset_company_name = '';
         }
         // A number was given instead of a name
         if (is_numeric($user_name)) {
             $this->comment('User ' . $user_name . ' is not a name - assume this user already exists');
             $user_username = '';
             // No name was given
         } elseif ($user_name == '') {
             $this->comment('No user data provided - skipping user creation, just adding asset');
             $first_name = '';
             $last_name = '';
             //$user_username = '';
         } else {
             $user_email_array = User::generateFormattedNameFromFullName($this->option('email_format'), $user_name);
             $first_name = $user_email_array['first_name'];
             $last_name = $user_email_array['last_name'];
             if ($user_email == '') {
                 $user_email = $user_email_array['username'] . '@' . Config::get('app.domain');
             }
             if ($user_username == '') {
                 if ($this->option('username_format') == 'email') {
                     $user_username = $user_email;
                 } else {
                     $user_name_array = User::generateFormattedNameFromFullName($this->option('username_format'), $user_name);
                     $user_username = $user_name_array['username'];
                 }
             }
         }
         $this->comment('Full Name: ' . $user_name);
         $this->comment('First Name: ' . $first_name);
         $this->comment('Last Name: ' . $last_name);
         $this->comment('Username: '******'Email: ' . $user_email);
         $this->comment('Category Name: ' . $user_asset_category);
         $this->comment('Item: ' . $user_asset_name);
         $this->comment('Manufacturer ID: ' . $user_asset_mfgr);
         $this->comment('Model No: ' . $user_asset_modelno);
         $this->comment('Serial No: ' . $user_asset_serial);
         $this->comment('Asset Tag: ' . $user_asset_tag);
         $this->comment('Location: ' . $user_asset_location);
         $this->comment('Purchase Date: ' . $user_asset_purchase_date);
         $this->comment('Purchase Cost: ' . $user_asset_purchase_cost);
         $this->comment('Notes: ' . $user_asset_notes);
         $this->comment('Company Name: ' . $user_asset_company_name);
         $this->comment('------------- Action Summary ----------------');
         if ($user_username != '') {
             if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) {
                 $this->comment('User ' . $user_username . ' already exists');
             } else {
                 // Create the user
                 $user = Sentry::createUser(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $user_email, 'username' => $user_username, 'password' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 12), 'activated' => true, 'permissions' => array('admin' => 0, 'user' => 1), 'notes' => 'User imported through asset importer'));
                 // Find the group using the group id
                 $userGroup = Sentry::findGroupById(3);
                 // Assign the group to the user
                 $user->addGroup($userGroup);
                 $this->comment('User ' . $first_name . ' created');
             }
         } else {
             $user = new User();
         }
         // Check for the location match and create it if it doesn't exist
         if ($location = Location::where('name', e($user_asset_location))->first()) {
             $this->comment('Location ' . $user_asset_location . ' already exists');
         } else {
             $location = new Location();
             if ($user_asset_location != '') {
                 $location->name = e($user_asset_location);
                 $location->address = '';
                 $location->city = '';
                 $location->state = '';
                 $location->country = '';
                 $location->user_id = 1;
                 if (!$this->option('testrun') == 'true') {
                     if ($location->save()) {
                         $this->comment('Location ' . $user_asset_location . ' was created');
                     } else {
                         $this->comment('Something went wrong! Location ' . $user_asset_location . ' was NOT created');
                     }
                 } else {
                     $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only');
                 }
             } else {
                 $this->comment('No location given, so none created.');
             }
         }
         if (e($user_asset_category) == '') {
             $category_name = 'Unnamed Category';
         } else {
             $category_name = e($user_asset_category);
         }
         // Check for the category match and create it if it doesn't exist
         if ($category = Category::where('name', e($category_name))->where('category_type', 'asset')->first()) {
             $this->comment('Category ' . $category_name . ' already exists');
         } else {
             $category = new Category();
             $category->name = e($category_name);
             $category->category_type = 'asset';
             $category->user_id = 1;
             if ($category->save()) {
                 $this->comment('Category ' . $user_asset_category . ' was created');
             } else {
                 $this->comment('Something went wrong! Category ' . $user_asset_category . ' was NOT created');
             }
         }
         // Check for the manufacturer match and create it if it doesn't exist
         if ($manufacturer = Manufacturer::where('name', e($user_asset_mfgr))->first()) {
             $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists');
         } else {
             $manufacturer = new Manufacturer();
             $manufacturer->name = e($user_asset_mfgr);
             $manufacturer->user_id = 1;
             if ($manufacturer->save()) {
                 $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created');
             } else {
                 $this->comment('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created');
             }
         }
         // Check for the asset model match and create it if it doesn't exist
         if ($asset_model = Model::where('name', e($user_asset_name))->where('modelno', e($user_asset_modelno))->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) {
             $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists');
         } else {
             $asset_model = new Model();
             $asset_model->name = e($user_asset_name);
             $asset_model->manufacturer_id = $manufacturer->id;
             $asset_model->modelno = e($user_asset_modelno);
             $asset_model->category_id = $category->id;
             $asset_model->user_id = 1;
             if ($asset_model->save()) {
                 $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created');
             } else {
                 $this->comment('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created');
             }
         }
         // Check for the asset company match and create it if it doesn't exist
         if ($user_asset_company_name != '') {
             if ($company = Company::where('name', e($user_asset_company_name))->first()) {
                 $this->comment('Company ' . $user_asset_company_name . ' already exists');
             } else {
                 $company = new Company();
                 $company->name = e($user_asset_company_name);
                 if ($company->save()) {
                     $this->comment('Company ' . $user_asset_company_name . ' was created');
                 } else {
                     $this->comment('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created');
                 }
             }
         } else {
             $company = new Company();
         }
         // Check for the asset match and create it if it doesn't exist
         if ($asset = Asset::where('asset_tag', e($user_asset_tag))->first()) {
             $this->comment('The Asset with asset tag ' . $user_asset_tag . ' already exists');
         } else {
             $asset = new Asset();
             $asset->name = e($user_asset_asset_name);
             if ($user_asset_purchase_date != '') {
                 $asset->purchase_date = $user_asset_purchase_date;
             } else {
                 $asset->purchase_date = NULL;
             }
             if ($user_asset_purchase_cost != '') {
                 $asset->purchase_cost = ParseFloat(e($user_asset_purchase_cost));
             } else {
                 $asset->purchase_cost = 0.0;
             }
             $asset->serial = e($user_asset_serial);
             $asset->asset_tag = e($user_asset_tag);
             $asset->model_id = $asset_model->id;
             $asset->assigned_to = $user->id;
             $asset->rtd_location_id = $location->id;
             $asset->user_id = 1;
             $asset->status_id = $status_id;
             $asset->company_id = $company->id;
             if ($user_asset_purchase_date != '') {
                 $asset->purchase_date = $user_asset_purchase_date;
             } else {
                 $asset->purchase_date = NULL;
             }
             $asset->notes = e($user_asset_notes);
             if ($asset->save()) {
                 $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created');
             } else {
                 $this->comment('Something went wrong! Asset ' . $user_asset_name . ' was NOT created');
             }
         }
         $this->comment('=====================================');
         return true;
     });
 }
 /**
  * @param Asset $asset
  * @return array|string
  */
 protected function getTreeNodeConfig($asset)
 {
     $tmpAsset = array("id" => $asset->getId(), "text" => $asset->getFilename(), "type" => $asset->getType(), "path" => $asset->getFullPath(), "basePath" => $asset->getPath(), "locked" => $asset->isLocked(), "lockOwner" => $asset->getLocked() ? true : false, "elementType" => "asset", "permissions" => array("remove" => $asset->isAllowed("delete"), "settings" => $asset->isAllowed("settings"), "rename" => $asset->isAllowed("rename"), "publish" => $asset->isAllowed("publish"), "view" => $asset->isAllowed("view")));
     // set type specific settings
     if ($asset->getType() == "folder") {
         $tmpAsset["leaf"] = false;
         $tmpAsset["expanded"] = $asset->hasNoChilds();
         $tmpAsset["iconCls"] = "pimcore_icon_folder";
         $tmpAsset["permissions"]["create"] = $asset->isAllowed("create");
     } else {
         $tmpAsset["leaf"] = true;
         $tmpAsset["iconCls"] = "pimcore_icon_" . Pimcore_File::getFileExtension($asset->getFilename());
     }
     $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId());
     if ($asset->getType() == "image") {
         try {
             $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId(), "text" => '<img src="/admin/asset/get-image-thumbnail/id/' . $asset->getId() . '/width/130/aspectratio/true" width="130" />', "width" => 140);
             // this is for backward-compatibilty, to calculate the dimensions if they are not there
             if (!$asset->getCustomSetting("imageDimensionsCalculated")) {
                 $asset->save();
             }
             if ($asset->getCustomSetting("imageWidth") && $asset->getCustomSetting("imageHeight")) {
                 $tmpAsset["imageWidth"] = $asset->getCustomSetting("imageWidth");
                 $tmpAsset["imageHeight"] = $asset->getCustomSetting("imageHeight");
             }
         } catch (Exception $e) {
             Logger::debug("Cannot get dimensions of image, seems to be broken.");
         }
     } else {
         if ($asset->getType() == "video") {
             try {
                 if (Pimcore_Video::isAvailable()) {
                     $tmpAsset["qtipCfg"] = array("title" => "ID: " . $asset->getId(), "text" => '<img src="/admin/asset/get-video-thumbnail/id/' . $asset->getId() . '/width/130/aspectratio/true" width="130" />', "width" => 140);
                 }
             } catch (Exception $e) {
                 Logger::debug("Cannot get dimensions of video, seems to be broken.");
             }
         }
     }
     $tmpAsset["cls"] = "";
     if ($asset->isLocked()) {
         $tmpAsset["cls"] .= "pimcore_treenode_locked ";
     }
     if ($asset->getLocked()) {
         $tmpAsset["cls"] .= "pimcore_treenode_lockOwner ";
     }
     return $tmpAsset;
 }
 public function store()
 {
     try {
         //gets the input from Backbone
         $newModel = Input::json()->all();
         //makes a new asset
         $newAsset = new Asset();
         //sets the properties of the new asset
         $newAsset->brand_name = $newModel['brand_name'];
         $newAsset->serial_number = $newModel['serial_number'];
         $newAsset->asset_tag = $newModel['asset_tag'];
         $newAsset->description = $newModel['description'];
         $newAsset->room = $newModel['room'];
         $newAsset->department_id = $newModel['department_id'];
         $newAsset->mac_address = $newModel['mac_address'];
         $newAsset->ip_address = $newModel['ip_address'];
         $newAsset->asset_type = $newModel['asset_type'];
         $newAsset->assignee_name = $newModel['assignee_name'];
         $newAsset->active = 1;
         //saves the asset to the Database
         $newAsset->save();
         //return the new asset
         return $newAsset->toJSON();
     } catch (Exception $e) {
         return json_encode('{"error":{"text":' . $e->getMessage() . '}}');
     }
 }