public function local() { // Local file upload try { if (empty($_FILES['file']) || !is_uploaded_file($_FILES['file']['tmp_name'])) { throw new Exception("Something went wrong with uploading this file. The file may be too large to upload."); } $tmp_file = $_FILES['file']; $dst = STORAGE_PATH . "/uploads/" . $tmp_file["name"]; $this->ensureGoodFile($tmp_file); if (file_exists($dst)) { unlink($dst); } // Create the directory structure if it doesn't exist if (!is_dir(dirname($dst))) { mkdir(dirname($dst), 0777, true); } rename($tmp_file["tmp_name"], $dst); $file = FileUploadHandler::fromName("uploads/" . $tmp_file["name"]); Activity::log("uploaded a new file called " . $file->getLink() . "."); //send us to step 2. $this->forwardToUrl("/job/create/file:{$file->id}"); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); } }
/** * After validate event * @return object */ public function afterValidate() { if (count($this->ids)) { $save = array(); // The values we would like to check if they were changed // key = value from this model // value = value from the tickets model $valuesChanged = array('status' => 'ticketstatus', 'type' => 'tickettype', 'category' => 'ticketcategory', 'priority' => 'priority', 'version' => 'ticketversion', 'fixedin' => 'fixedin', 'assignedtoid' => 'assignedtoid'); // Loop the values foreach ($valuesChanged as $key => $value) { if ($this->{$key}) { $save[$value] = $this->{$key}; } } // Only update if we have any if (count($save)) { // Update all the ticket ids Tickets::model()->updateByPk($this->ids, $save); // Load one ticket model $model = Tickets::model()->findByPk(reset($this->ids)); $this->activity['projectid'] = $model->projectid; $this->activity['type'] = Activity::TYPE_TICKET; $this->activity['title'] = 'Used multi-Moderation to update <strong>{n}</strong> {title}.'; // Append project params $this->activity['params'] = array_merge($this->activity['params'], array('{n}' => count($this->ids), '{title}' => CHtml::link(Yii::t('tickets', 'Tickets'), array('/tickets')))); // Activity: New Project Activity::log($this->activity); } } return parent::afterValidate(); }
public function create() { $this->assertLoggedIn(); $this->setTitle('Create a New Queue'); if ($this->args('submit')) { //did we get a name? if (!$this->args('name')) { $errors['name'] = "You need to provide a name."; $errorfields['name'] = 'error'; } //okay, we good? if (empty($errors)) { //woot! $q = new Queue(); $q->set('name', $this->args('name')); $q->set('user_id', User::$me->id); $q->save(); //todo: send a confirmation email. Activity::log("created a new queue named " . $q->getLink() . "."); $this->forwardToUrl($q->getUrl()); } else { $this->set('errors', $errors); $this->set('errorfields', $errorfields); $this->setArg('name'); } } }
public function Parallax() { $menus = Menu::roots()->get(); $menu = Menu::where('slug', '/anasayfa')->first(); \Activity::log('Ziyaret: Anasayfa (Tek Sayfa Site)'); return view('parallax')->with(['menus' => $menus, 'menu' => $menu]); }
public function destroy($id) { Admin::where('id', '=', $id)->delete(); Activity::log(['contentId' => $id, 'user_id' => Auth::admin()->get()->id, 'contentType' => 'Administrador', 'action' => 'Delete ', 'description' => 'Eliminacion de un administrador', 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); $output['success'] = 'deleted'; return Response::json($output, 200); }
public function createRetailerOnSignUp($user, $data) { $retailer = new Retailer(); $retailer->admin_id = $user->id; $retailer->category_id = $data['category']; $retailer->name = $data['spaname']; $retailer->save(); Activity::log(['contentId' => $retailer->id, 'contentType' => 'Retailer', 'action' => 'Create', 'description' => 'Created a retailer', 'details' => 'Retailer Name: ' . $retailer->name, 'updated' => false]); }
/** * Restore revision log * */ public function restoreRevisionLog($revisionId) { $this->activity['projectid'] = $this->page->projectid; $this->activity['type'] = Activity::TYPE_WIKI; $this->activity['title'] = "Restored Revision <strong>{revid}</strong> for the page <strong>{pagetitle}</strong> "; // Append project params $this->activity['params'] = array_merge($this->activity['params'], array('{revid}' => WikiPages::model()->getModelRevisionLink($revisionId, $this->page->id, $this->page->alias), '{pagetitle}' => $this->page->getLink())); // Activity: New Project Activity::log($this->activity); }
public function destroy($id) { if (Request::ajax()) { Donacion::destroy($id); $output['success'] = 'deleted'; Activity::log(['contentId' => $id, 'contentType' => 'Donacion', 'user_id' => Auth::admin()->get()->id, 'action' => 'Update', 'description' => 'Eliminacion de Donacion ' . $id, 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); return Response::json($output, 200); } else { throw new Exception('Wrong request'); } }
/** * Download Subscribes * */ public function subscribes() { $subscribes = Subscribe::all('email')->toArray(); $file = ''; foreach ($subscribes as $key => $subscribe) { $file .= $key == 0 ? $subscribe['email'] : "\r\n" . $subscribe['email']; } $path = storage_path('app/subscribes.txt'); \File::put($path, $file); \Activity::log('Abone Listesi İndirildi'); return response()->download($path)->deleteFileAfterSend(true); }
public function success() { $this->assertLoggedIn(); //handle our upload try { $file = FileUploadHandler::fromName($this->args('key')); Activity::log("uploaded a new file called " . $file->getLink() . "."); //send us to step 2. $this->forwardToUrl("/job/create/file:{$file->id}"); } catch (Exception $e) { $this->setTitle("Upload File - Error"); $this->set('megaerror', $e->getMessage()); } }
/** * afterSave event * */ public function afterSave() { $this->activity['projectid'] = $this->projectid; $this->activity['type'] = Activity::TYPE_TICKET; if ($this->isNewRecord) { $this->activity['title'] = 'Created a new ticket <strong>{tickettitle}</strong>'; } else { $this->activity['title'] = 'Updated ticket <strong>{tickettitle}</strong>'; } // Append project params $this->activity['params'] = array_merge($this->activity['params'], array('{tickettitle}' => $this->getLink())); // Activity: New Project Activity::log($this->activity); return parent::afterSave(); }
public function forgotpass() { $this->setTitle("Retrieve Forgotten Password"); if ($this->args('submit')) { $user = User::byEmail($this->args('email')); if ($user->isHydrated()) { //give them a pass hash. $user->set('pass_reset_hash', sha1(mt_rand() . mt_rand() . mt_rand())); $user->save(); $link = "http://" . SITE_HOSTNAME . $user->getUrl() . "/resetpass:"******"forgot his/her password. :P", $user); Email::queue($user, "Password Reset", $text, $html); $this->set('status', "We have sent a reset password confirmation email to '" . $this->args('email') . "'."); } else { $this->set('error', "We could not find an account with that email address."); } $this->setArg('email'); } }
public function success() { $this->assertLoggedIn(); //get our payload. $payload = unserialize(base64_decode($this->args('payload'))); //handle our upload try { //some basic error checking. if (!preg_match('/gcode$/i', $this->args('key'))) { throw new Exception("Only .gcode files are allowed at this time."); } //make our file. $info = $this->_lookupFileInfo(); $file = $this->_createS3File(); Activity::log("uploaded a new file called " . $file->getLink() . "."); //send us to step 2. $this->forwardToUrl("/job/create/file:{$file->id}"); } catch (Exception $e) { $this->setTitle("Upload File - Error"); $this->set('megaerror', $e->getMessage()); } }
public function getTimeSlot($service_id) { Activity::log(['contentId' => $service_id, 'contentType' => 'Outlet', 'action' => 'getTimeSlot', 'description' => 'getTimeSlot of Service', 'details' => 'Service Id: ' . $service_id, 'updated' => false]); $service = Service::find($service_id); $outlet = Outlet::find($service->outlet_id); $startTime = explode(':', $outlet->startTime); $endTime = explode(':', $outlet->endTime); if (count($startTime) < 2 || count($endTime) < 2) { return array(); } $start = mktime($startTime[0], $startTime[1], 0, 8, 12, 2014); $end = mktime($endTime[0], $endTime[1], 0, 8, 12, 2014); $hourArray = array(); $count = 1; $hourArray[] = $start; while ($start < $end && $count < 1000) { $date = $start + $service->time_operate * 60; $hourArray[] = $date; $start = $date; $count++; } return $hourArray; }
function add_comment() { $this->assertLoggedIn(); try { $this->setTitle('Add Comment'); $content_id = $this->args('content_id'); $content_type = $this->args('content_type'); $content = Comment::getContent($content_id, $content_type); if (!is_object($content)) { throw new Exception("That content does not exist."); } if (!$content->isHydrated()) { throw new Exception("That content does not exist."); } if (!$content->canComment()) { throw new Exception("You cannot comment on this content."); } $form = $this->_createAddCommentForm($content_id, $content_type); //handle our form if ($form->checkSubmitAndValidate($this->args())) { $comment = new Comment(); $comment->set('content_id', $form->data('content_id')); $comment->set('content_type', $form->data('content_type')); $comment->set('comment', $form->data('comment')); $comment->set('user_id', User::$me->id); $comment->set('comment_date', date("Y-m-d H:i:s")); $comment->save(); Activity::log("commented on " . $content->getLink() . "."); $this->forwardToUrl($content->getUrl()); } $this->set('form', $form); } catch (Exception $e) { $this->setTitle('Add Comment - Error'); $this->set('megaerror', $e->getMessage()); } }
public static function boot() { parent::boot(); if (!static::$logActivities) { return true; } // Attach to created event static::created(function ($model) { Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Created', 'description' => 'Created ' . get_class($model)]); }); static::deleted(function ($model) { Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Deleted', 'description' => 'Deleted ' . get_class($model)]); }); static::updating(function ($model) { $details = ''; // Get changes in model foreach ($model->getDirty() as $attribute => $value) { $original = $model->getOriginal($attribute); $details .= "{$attribute}: from '{$original}' to '{$value}'\r\n"; } // Do not log if there's no changes if (!empty($details)) { Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Updated', 'description' => 'Updated ' . get_class($model), 'details' => trim($details)]); } }); }
/** * Sort the specified resource from storage. * */ public function sort() { foreach (\Input::get('people') as $key => $id) { Person::find($id)->update(['line' => $key]); } \Activity::log('Kişilerin Sıralaması Değiştirildi'); }
/** * Simply saves the given instance * * @param User $instance * * @return boolean Success */ public function save(User $instance) { Activity::log(['contentId' => 0, 'contentType' => 'User', 'action' => 'Update', 'description' => 'Update user info', 'details' => 'Username: '******'updated' => false]); return $instance->save(); }
public function api_updateslicejob() { if (!$this->args('job_id')) { throw new Exception("You must provide the 'bot_id' parameter."); } $sj = new SliceJob($this->args('job_id')); if (!$sj->isHydrated()) { throw new Exception("Slice job does not exist."); } if ($sj->get('user_id') != User::$me->id) { throw new Exception("This slice job is not yours."); } //load up our objects $job = $sj->getJob(); //upload our file $file = $_FILES['file']; $emptyFile = false; try { $this->ensureGoodFile($file); } catch (InvalidUploadedFile $ex) { if ($ex->getCode() == UPLOAD_ERR_EMPTY) { $emptyFile = true; } else { throw $ex; } } $data_file = Storage::newFile(); if (!$emptyFile) { //okay, we're good.. do it. $data_file->set('user_id', User::$me->id); $data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($file['name'])); } //update our status. $sj->set('output_log', $this->args('output')); $sj->set('error_log', $this->args('errors')); if (!$emptyFile) { $sj->set('output_id', $data_file->id); } $sj->save(); //update our job $job->set('slice_complete_time', date("Y-m-d H:i:s")); if (!$emptyFile) { $job->set('file_id', $data_file->id); } $job->save(); //what do do with it now? if ($this->args('status') == 'complete') { $sj->pass(); } else { if ($this->args('status') == 'failure') { $sj->fail(); } else { if ($this->args('status') == 'pending') { $sj->setStatus('pending'); $sj->set('finish_date', date("Y-m-d H:i:s")); $sj->save(); } } } Activity::log($job->getBot()->getLink() . " sliced the " . $job->getLink() . " job via the API."); return $job->getBot()->getAPIData(); }
public function login() { $loginForm = $this->_createLoginForm(); $this->set('login_form', $loginForm); if ($loginForm->checkSubmitAndValidate($this->args())) { $username = $this->args('username'); $password = $this->args('password'); $rememberMe = $this->args('remember_me'); User::login($username, $password); if (User::isLoggedIn()) { //Want a cookie? if ($rememberMe) { $token = User::$me->createToken(); $token->setCookie(); } Activity::log("logged in."); //send us! $this->forwardToURL('/'); } else { $this->set('error', "We could not find that username/password combination"); } } }
public function flush() { $this->assertLoggedIn(); $this->set('area', 'queues'); try { //how do we find them? $queue = new Queue($this->args('id')); //did we really get someone? if (!$queue->isHydrated()) { throw new Exception("Could not find that queue."); } if ($queue->get('user_id') != User::$me->id) { throw new Exception("You do not own this queue."); } $this->set('queue', $queue); $this->setTitle('Empty Queue - ' . $queue->getName()); if ($this->args('submit')) { Activity::log("emptied the queue <strong>" . $queue->getName() . "</strong>."); $queue->flush(); $this->forwardToUrl($queue->getUrl()); } } catch (Exception $e) { $this->setTitle('Empty Queue - Error'); $this->set('megaerror', $e->getMessage()); } }
public function revoke_app() { $this->assertLoggedIn(); try { $token = OAuthToken::findByKey($this->args('token')); if (!$token->isHydrated()) { throw new Exception("This app does not exist."); } if (!User::$me->isAdmin() && $token->get('user_id') != User::$me->id) { throw new Exception("You are not authorized to delete this app."); } $app = $token->getConsumer(); $this->setTitle('Revoke App Permissions - ' . $app->getName()); $this->set('token', $token); $this->set('app', $app); if ($this->args('submit')) { Activity::log("removed the app named " . $app->getLink() . "."); $token->delete(); $this->forwardToUrl("/apps"); } } catch (Exception $e) { $this->setTitle('Error'); $this->set('megaerror', $e->getMessage()); } }
public function cancel($token) { switch ($token) { case 'now': $this->runCancel('', array('id' => $this->id)); break; case 'later': $date = Carbon::now()->addMinutes(15); Queue::later($date, 'UserController@runCancel', array('id' => $this->id)); break; case 'tomorrow': $date = Carbon::tomorrow(); Queue::later($date, 'UserController@runCancel', array('id' => $this->id)); break; case 'disable': if ($this->cancelled) { DB::table('users')->where('id', $this->id)->update(array('confirmed' => true, 'cancelled' => false)); } break; } Activity::log(array('contentID' => $this->id, 'contentType' => 'account_cancelled', 'description' => $this->id, 'details' => '', 'updated' => $this->id)); }
} return $view->nest('commentForm', 'default/site/blog/comment_form', array('post' => $viewdata['post'])); }); Route::filter('json', function () { Api::$type = 'json'; }); Route::filter('xml', function () { Api::$type = 'xml'; }); Route::when('json', 'json'); Route::when('xml', 'xml'); Route::filter('checkuser', function () { if (Auth::check()) { DB::update('UPDATE users SET last_activity = ? WHERE id = ?', array(date('Y-m-d H:i:s', time()), Auth::user()->id)); if (!Request::ajax()) { Activity::log(array('contentID' => Confide::user()->id, 'contentType' => 'activity', 'description' => 'Page Loaded', 'details' => '<a href="' . $_SERVER['REQUEST_URI'] . '" target="_new" class="btn">link</a>', 'updated' => Confide::user()->id ? true : false)); } $value = Cache::remember('valid_user', '1', function () { return Auth::user()->confirmed != '1' ? true : false; }); if ($value) { Confide::logout(); return Redirect::to('suspended'); } } }); Route::filter('auth', function ($route, $request) { if (Auth::guest()) { Session::put('loginRedirect', Request::url()); return Redirect::to('user/login/'); }
/** * send a mail * * @return Response */ private function sendEmail($user, $template = 'emails.default') { //if (!View::exists($template))$template='emails.default'; Event::fire('controller.user.email', array($user)); $this->email = $user->email; try { $send = Mail::send($template, array('body' => Input::get('body'), 'user' => $user), function ($message) { $message->to($this->email)->subject(Input::get('subject')); $files = Input::file('email_attachment'); if (count($files) > 1) { foreach ($files as $file) { $message->attach($file->getRealPath(), array('as' => $file->getClientOriginalName(), 'mime' => $file->getMimeType())); } } elseif (count($files) == 1) { $message->attach($files->getRealPath(), array('as' => $files->getClientOriginalName(), 'mime' => $files->getMimeType())); } }); Activity::log(array('contentID' => $user->id, 'contentType' => 'email', 'description' => Input::get('subject'), 'details' => Input::get('body'), 'updated' => $user->id ? true : false)); } catch (Exception $e) { return false; } return $send; }
public function edit() { $this->assertLoggedIn(); $this->set('area', 'bots'); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } else { throw new Exception("Could not find that bot."); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } $this->setTitle('Edit Bot - ' . $bot->getName()); $wizard = new Wizard('bot', $this->args()); if (!$this->args('setup')) { $wizard->disableWizardMode(); } // Create our forms $infoForm = $this->_createInfoForm($bot); $queuesForm = $this->_createQueueForm($bot); $slicingForm = $this->_createSlicingForm($bot); $driverForm = $this->_createDriverForm($bot); // Add them to the wizard $wizard->add("Information / Details", $infoForm); $wizard->add("Queues", $queuesForm); $wizard->add("Slicing Setup", $slicingForm); $wizard->add("Driver Configuration", $driverForm); //handle our forms if ($infoForm->checkSubmitAndValidate($this->args())) { $bot->set('name', $infoForm->data('name')); $bot->set('manufacturer', $infoForm->data('manufacturer')); $bot->set('model', $infoForm->data('model')); $bot->set('electronics', $infoForm->data('electronics')); $bot->set('firmware', $infoForm->data('firmware')); $bot->set('extruder', $infoForm->data('extruder')); $bot->save(); Activity::log("edited the information for bot " . $bot->getLink() . "."); } else { if ($queuesForm->checkSubmitAndValidate($this->args())) { $sql = "DELETE FROM bot_queues WHERE bot_id = ?"; db()->execute($sql, array($bot->id)); $priority = 1; $used = array(); foreach ($this->args() as $key => $value) { if (substr($key, 0, 6) === "queue-" && $value != 0) { if (in_array($value, $used)) { continue; } else { $used[] = $value; } $sql = "INSERT INTO bot_queues VALUES(?, ?, ?)"; $data = array($value, $bot->id, $priority); $priority++; db()->execute($sql, $data); } } } else { if ($slicingForm->checkSubmitAndValidate($this->args())) { $bot->set('slice_engine_id', $slicingForm->data('slice_engine_id')); $bot->set('slice_config_id', $slicingForm->data('slice_config_id')); $config = $bot->getDriverConfig(); $config->can_slice = (bool) $slicingForm->data('can_slice'); $bot->set('driver_config', json::encode($config)); $bot->save(); Activity::log("edited the slicing info for bot " . $bot->getLink() . "."); } else { if ($driverForm->checkSubmitAndValidate($this->args())) { $bot->set('oauth_token_id', $driverForm->data('oauth_token_id')); $bot->set('driver_name', $driverForm->data('driver_name')); //create and save our config $config = $bot->getDriverConfig(); $config->driver = $bot->get('driver_name'); if ($bot->get('driver_name') == 'dummy') { if ($this->args('delay')) { $config->delay = $this->args('delay'); } } elseif ($bot->get('driver_name') == 'printcore' || $bot->get('driver_name') == 's3g') { $config->port = $this->args('serial_port'); $config->port_id = $this->args('port_id'); $config->baud = $this->args('baudrate'); } //did we get webcam info? if ($this->args('webcam_device')) { if (!isset($config->webcam)) { $config->webcam = new stdClass(); } $config->webcam->device = $this->args('webcam_device'); if ($this->args('webcam_id')) { $config->webcam->id = $this->args('webcam_id'); } if ($this->args('webcam_name')) { $config->webcam->name = $this->args('webcam_name'); } if ($this->args('webcam_brightness')) { $config->webcam->brightness = (int) $this->args('webcam_brightness'); } if ($this->args('webcam_contrast')) { $config->webcam->contrast = (int) $this->args('webcam_contrast'); } } else { unset($config->webcam); } //save it all to the bot as json. $bot->set('driver_config', json::encode($config)); $bot->save(); Activity::log("edited the driver configuration for bot " . $bot->getLink() . "."); } } } } if ($wizard->isFinished()) { $this->forwardToURL($bot->getUrl()); } $this->set('bot_id', $bot->id); $this->set('wizard', $wizard); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("Bot Edit - Error"); } }
public function destroy($id) { Personal::where('personalID', '=', $id)->delete(); Activity::log(['contentId' => $id, 'contentType' => 'Personal', 'user_id' => Auth::admin()->get()->id, 'action' => 'Borrado de Personal Aportante', 'description' => 'Borrado de Personal Aportante ', 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $id ? true : false]); $output['success'] = 'deleted'; return Response::json($output, 200); }
public function api_updatebot() { if (!$this->args('bot_id')) { throw new Exception("You must provide the 'bot_id' parameter."); } $bot = new Bot($this->args('bot_id')); if (!$bot->isHydrated()) { throw new Exception("Bot does not exist."); } if (!$bot->isMine()) { throw new Exception("This bot is not yours."); } //if (!$this->args('manufacturer')) // throw new Exception('Bot manufacturer is a required parameter.'); //if (!$this->args('model')) // throw new Exception('Bot model is a required parameter.'); if ($this->args('name')) { $bot->set('name', $this->args('name')); } if ($this->args('name')) { $bot->set('identifier', $this->args('identifier')); } if ($this->args('manufacturer')) { $bot->set('manufacturer', $this->args('manufacturer')); } if ($this->args('model')) { $bot->set('model', $this->args('model')); } if ($this->args('electronics')) { $bot->set('electronics', $this->args('electronics')); } if ($this->args('firmware')) { $bot->set('firmware', $this->args('firmware')); } if ($this->args('extruder')) { $bot->set('extruder', $this->args('extruder')); } if ($this->args('status')) { $bot->set('status', $this->args('status')); } if ($this->args('error_text')) { $bot->set('error_text', $this->args('error_text')); } $bot->save(); Activity::log("updated the bot " . $bot->getLink() . " via the API."); return $bot->getAPIData(); }
/** * Update start page * @param int $pageId */ public function makeStartPage() { Yii::app()->db->createCommand('UPDATE {{wiki_pages}} SET isstartpage=0')->execute(); $this->isstartpage = 1; $this->activity['projectid'] = $this->projectid; $this->activity['type'] = Activity::TYPE_WIKI; $this->activity['title'] = "Marked <strong>{pagetitle}</strong> as a start page."; // Append project params $this->activity['params'] = array_merge($this->activity['params'], array('{pagetitle}' => $this->getLink())); // Activity: New Project Activity::log($this->activity); Activity::$toSave = false; $this->update(); }
/** * Sort the specified resource from storage. * */ public function sort() { foreach (\Input::get('contents') as $key => $id) { Content::find($id)->update(['line' => $key]); } \Activity::log('Menu Id: ' . $id . ' | İçerik Sıralaması Değiştirildi'); }