Example #1
0
 public function onUpdateDocument(DataSource_Hybrid_Document $old = NULL, DataSource_Hybrid_Document $new)
 {
     $files = Arr::get($_FILES, $this->name);
     $remove_files = $new->get($this->name . '_remove');
     if (!empty($remove_files)) {
         ORM::factory('media')->delete_by_ids($remove_files);
     }
     if (empty($files)) {
         return FALSE;
     }
     $old_files = $old->get($this->name);
     $old_files = empty($old_files) ? array() : explode(',', $old_files);
     $files = $this->_normalize_files($files);
     foreach ($files as $file) {
         if (!Upload::not_empty($file)) {
             continue;
         }
         try {
             $uploaded_file = ORM::factory('media')->set('module', $this->module_id())->upload($file, array('jpg', 'jpeg', 'gif', 'png'), $this->max_size);
             if ($uploaded_file->loaded()) {
                 $old_files[] = $uploaded_file->id;
             }
         } catch (Exception $ex) {
             continue;
         }
     }
     $new->set($this->name, implode(',', $old_files));
     return TRUE;
 }
Example #2
0
 public function get_available_langs()
 {
     $langs = I18n::available_langs();
     $system_default = Arr::get($langs, Config::get('site', 'default_locale'));
     $langs[Model_User::DEFAULT_LOCALE] = __('System default (:locale)', array(':locale' => $system_default));
     return $langs;
 }
Example #3
0
 /**
  * Override of the set_cache method, works in exactly the same way except
  * the check for the max-age header in the response has been removed so that
  * Codebase API responses will always be cached, this breaks HTTP Cache
  * rules but is the cleanest way of enabling caching for all responses
  * within Kohana.
  *
  * @param	Response	$response
  * @return	boolean
  */
 public function set_cache(Response $response)
 {
     $headers = $response->headers()->getArrayCopy();
     if ($cache_control = Arr::get($headers, 'cache-control')) {
         // Parse the cache control
         $cache_control = HTTP_Header::parse_cache_control($cache_control);
         // If the no-cache or no-store directive is set, return
         if (array_intersect($cache_control, array('no-cache', 'no-store'))) {
             return FALSE;
         }
         // Check for private cache and get out of here if invalid
         if (!$this->_allow_private_cache and in_array('private', $cache_control)) {
             if (!isset($cache_control['s-maxage'])) {
                 return FALSE;
             }
             // If there is a s-maxage directive we can use that
             $cache_control['max-age'] = $cache_control['s-maxage'];
         }
     }
     /**
      * if the max-age cache control header is set to 0 in the response, set
      * it to 1 hour so the reponse will be cacheable
      */
     $cache_control_header = $response->headers('Cache-Control');
     $response->headers('Cache-Control', str_replace('max-age=0', 'max-age=3600', $cache_control_header));
     if ($expires = Arr::get($headers, 'expires') and !isset($cache_control['max-age'])) {
         // Can't cache things that have expired already
         if (strtotime($expires) <= time()) {
             return FALSE;
         }
     }
     return TRUE;
 }
Example #4
0
 /**
  * Verify the login result and do whatever is needed to access the user data from this provider.
  * @return bool
  */
 public function verify()
 {
     // create token
     $request_token = OAuth_Token::factory('request', array('token' => Session::instance()->get('oauth_token'), 'secret' => Session::instance()->get('oauth_token_secret')));
     // Store the verifier in the token
     $verifier = Arr::get($_REQUEST, 'oauth_verifier');
     if (empty($verifier)) {
         return false;
     }
     $request_token->verifier($verifier);
     // Exchange the request token for an access token
     $access_token = $this->provider->access_token($this->consumer, $request_token);
     if ($access_token and $access_token->name === 'access') {
         $request = OAuth_Request::factory('resource', 'GET', 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,email-address)?format=json', array('oauth_consumer_key' => $this->consumer->key, 'oauth_signature_method' => "HMAC-SHA1", 'oauth_token' => $access_token->token));
         // Sign the request using only the consumer, no token is available yet
         $request->sign(new OAuth_Signature_HMAC_SHA1(), $this->consumer, $access_token);
         // decode and store data
         $data = json_decode($request->execute(), true);
         $this->uid = $data['id'];
         $this->data = $data;
         return true;
     } else {
         return false;
     }
 }
Example #5
0
 public function action_add()
 {
     if (!$this->user->id) {
         $this->redirect('/');
     }
     $comment = new Model_Comment();
     $comment->article_id = Arr::get($_POST, 'article_id');
     $comment->text = Arr::get($_POST, 'text');
     $comment->parent_id = Arr::get($_POST, 'parent_id', '0');
     $comment->user_id = $this->user->id;
     if (preg_match('(^[0-9]{1,})', $comment->article_id) != true) {
         $this->redirect('/');
     }
     if ($comment->text == '') {
         $this->redirect('/article/' . $comment->article_id);
     }
     if ($comment->parent_id != 0) {
         $parent_comment = Model_Comment::get($comment->parent_id);
         if ($parent_comment->parent_id != 0) {
             $comment->root_id = $parent_comment->root_id;
         } else {
             $comment->root_id = $parent_comment->id;
         }
     } else {
         $comment->root_id = 0;
     }
     $comment->insert();
     $this->redirect('/article/' . $comment->article_id);
 }
Example #6
0
 protected function submit($task, $id, $type)
 {
     $item = Jelly::select($type, $id);
     $redirect = HTML::uri(array('action' => Inflector::plural($type)));
     switch ($task) {
         case 'apply':
             $item->set($_POST)->save();
             $redirect = HTML::uri(array('action' => $type, 'task' => 'edit', 'id' => $item->id));
             $this->request->redirect($redirect);
             break;
         case 'save':
             $item->set($_POST)->save();
             $this->request->redirect($redirect);
             break;
         case 'cancel':
             $this->request->redirect($redirect);
             break;
         case 'delete':
             if ($ids = Arr::get($_POST, 'cid', NULL)) {
                 $items = Jelly::delete($item)->where(':primary_key', 'IN', $ids)->execute();
             }
             $this->request->redirect($redirect);
             break;
         case 'default':
             if (!$item->loaded()) {
                 $this->request->redirect($redirect);
             }
             break;
     }
     return $item;
 }
Example #7
0
 protected function load($menu = null)
 {
     $menu = $menu ?: $this->menu;
     $data = \Config::load('menu/' . $menu, true, true, true);
     $this->meta = array('name' => \Arr::get($data, 'name'), 'identifier' => \Arr::get($data, 'slug'), 'num_items' => $this->count($data['children']));
     return $data;
 }
Example #8
0
 /**
  * Редактирование акции
  * @return void
  */
 public function action_edit()
 {
     $stock = ORM::factory('stock', $this->request->param('id', NULL));
     if (!$stock->loaded()) {
         Message::set(Message::ERROR, Kohana::message('admin', 'stock_not_found'));
         $this->request->redirect('admin/service/stock');
     }
     if ($_POST) {
         try {
             $stock->values($_POST, array('text'));
             $stock->active = Arr::get($_POST, 'active', 0);
             $stock->update();
             Message::set(Message::SUCCESS, 'Акция отредактиована');
             $this->request->redirect('admin/service/stock');
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     } else {
         $this->values = $stock->as_array();
     }
     $this->view = View::factory('backend/stock/form')->set('url', 'admin/service/stock/edit/' . $stock->id)->set('errors', $this->errors)->set('values', $this->values);
     $this->template->title = 'Редактирования акции';
     $this->template->bc['#'] = 'Редактирования акции ' . $stock->service->name;
     $this->template->content = $this->view;
 }
Example #9
0
 public function action_show()
 {
     $id = Arr::get($_GET, 'id');
     $state = intval(Arr::get($_GET, 'state'));
     DB::update('job_columns')->set(array('show_reports' => $state))->where('id', '=', $id)->execute();
     die(json_encode(array('success' => true)));
 }
Example #10
0
 protected function init()
 {
     $module_config = Helper_Module::load_config('blog');
     $helper_acl = new Helper_ACL($this->acl);
     $helper_acl->inject(Arr::get($module_config, 'a2'));
     $this->blog_group = Arr::get($this->params, 'group');
 }
Example #11
0
File: posts.php Project: nnc/apis
	/**
	 * Retrieve posts.
	 *
	 *		Blogger::factory('posts')->read($consumer, $token, $blog_id, NULL, array('orderby' => 'updated'));
	 *
	 * IMPORTANT: define categories in parameters like this: array('categories' => '/Fritz/Laurie')
	 *
	 * @param   OAuth_Consumer	consumer
	 * @param   OAuth_Token		token
	 * @param   string			blog ID
	 * @param   string			post ID for a single post, if set to NULL all posts are retrieved
	 * @param   array			optional query parameters for search: http://code.google.com/apis/blogger/docs/2.0/developers_guide_protocol.html#RetrievingWithQuery
	 * @return  mixed
	 */
	public function read(OAuth_Consumer $consumer, OAuth_Token $token, $blog_id, $post_id = NULL, array $params = NULL)
	{
		// Look for categories in params
		if ($categories = Arr::get($params, 'categories'))
		{
			// Set post_id to '-' if categories are found
			$post_id = '-';
		}

		// Categories must not in query parameters
		unset($params['categories']);

		// Create a new GET request with the required parameters
		$request = OAuth_Request::factory('resource', 'GET', $this->url($blog_id, "posts/default/{$post_id}{$categories}"), array(
				'oauth_consumer_key' => $consumer->key,
				'oauth_token' => $token->token,
			));

		if ($params)
		{
			// Load user parameters
			$request->params($params);
		}

		// Sign the request using the consumer and token
		$request->sign($this->signature, $consumer, $token);

		// Create a response from the request
		$response = $request->execute();

		return $this->parse($response);
	}
Example #12
0
 public function add_tags($data, $photo)
 {
     $tag = ORM::factory('tag');
     $tags = Arr::get($data, 'tags');
     $tags = explode(',', $tags);
     foreach ($tags as $tag) {
         $tag = strtolower($tag);
         $tag = trim($tag);
         //removes extra whitespace
         $tag = strip_tags($tag);
         $tag = htmlentities($tag);
         if ($tag != '' and !empty($tag)) {
             $check = ORM::factory('tag')->where('name', '=', $tag)->find();
             if ($check->loaded()) {
                 if (!$check->has('photos', $photo)) {
                     $check->add('photos', $photo);
                 }
             } else {
                 $check->name = $tag;
                 $check->save();
                 $check->add('photos', $photo);
                 $this->action_build(false);
             }
         }
     }
 }
Example #13
0
 public function index()
 {
     $group = $this->config->item('admin_group', 'ion_auth');
     $ia = new Ion_auth_model();
     $limit = $this->config->config['users_on_page'];
     $page = !empty($_GET['page']) ? $_GET['page'] : 1;
     if ($page == 1) {
         $offset = '';
     } else {
         $offset = $limit * ($page - 1);
     }
     $searchText = Arr::get($_GET, 'search', '');
     $filter = Arr::get($_GET, 'filter', '');
     $admins = $ia->getUsersByGroup($group);
     if ($searchText || $filter !== '') {
         $admins->search($searchText, $filter, null, $limit, $offset);
         JsSettings::instance()->add(array('search' => $searchText, 'filter' => $filter, 'group' => $group));
     } else {
         if ($admins) {
             $admins->get($limit, $offset);
         }
     }
     $this->template->set('users', $admins);
     $this->template->set('group', $group);
     $this->template->set('limit', $limit);
     $this->template->set('page', $page);
     $this->template->set('c_user', $this->c_user);
     $this->template->render();
 }
Example #14
0
 public function action_index()
 {
     $code = $this->request->param('code');
     if ($code === NULL) {
         Model_Page_Front::not_found();
     }
     $reflink_model = ORM::factory('user_reflink', $code);
     if (!$reflink_model->loaded()) {
         Messages::errors(__('Reflink not found'));
         $this->go_home();
     }
     $next_url = Arr::get($reflink_model->data, 'next_url');
     try {
         Database::instance()->begin();
         Reflink::factory($reflink_model)->confirm();
         $reflink_model->delete();
         Database::instance()->commit();
     } catch (Kohana_Exception $e) {
         Database::instance()->rollback();
         Messages::errors($e->getMessage());
     }
     if (Valid::url($next_url)) {
         $this->go($next_url);
     }
     $this->go_home();
 }
Example #15
0
 public static function input($name, $value = NULL, array $attributes = NULL)
 {
     if (static::$model) {
         if (isset(static::$model->table_columns()[$name])) {
             if ($value === NULL) {
                 switch (Arr::get($attributes, 'type')) {
                     case 'checkbox':
                     case 'radio':
                         $attributes['checked'] = static::$model->{$name} == $value;
                         break;
                     case '':
                     case 'text':
                     case 'hidden':
                     case 'email':
                     case 'url':
                     case 'search':
                     case 'date':
                     case 'datetime':
                     case 'time':
                     case 'month':
                     case 'week':
                     case 'color':
                     case 'number':
                     case 'range':
                         $value = static::$model->{$name};
                         break;
                 }
             }
             $attributes['id'] = static::$model_name . '_' . URL::title($name);
             $name = static::$model_name . '[' . $name . ']';
         }
     }
     return parent::input($name, $value, $attributes);
 }
Example #16
0
 public function action_stats()
 {
     $data = array();
     $errors = array();
     $filter = Session::instance()->get('statFilter', array());
     if ($this->isPressed('btnFilter')) {
         $filter['FIO'] = Arr::get($_POST, 'FIO');
         $filter['dateFrom'] = Arr::get($_POST, 'dateFrom');
         $filter['dateTo'] = Arr::get($_POST, 'dateTo');
         Session::instance()->set('statFilter', $filter);
         if ($filter['dateFrom'] != '' && !Valid::mydate($filter['dateFrom'])) {
             $errors['dateFrom'] = 'Дата должна быть в формате dd.mm.yyyy';
         }
         if ($filter['dateTo'] != '' && !Valid::mydate($filter['dateTo'])) {
             $errors['dateTo'] = 'Дата должна быть в формате dd.mm.yyyy';
         }
     }
     $material_id = $this->request->param('id', NULL);
     $material = ORM::factory('material', $material_id);
     $data['materialName'] = $material->materialName;
     $data['stats'] = $material->getStats($material_id, $filter);
     $data['count'] = count($data['stats']);
     $data['filter'] = $filter;
     $data['errors'] = $errors;
     $this->tpl->content = View::factory('materials/stats', $data);
 }
Example #17
0
 /**
  * Gets a property from instance data.
  *
  * @param string $key     The key to get from data.
  * @param mixed  $default The default value to use if key not found.
  *
  * @return mixed
  */
 public function data($key = null, $default = null)
 {
     if (!empty($key)) {
         return Arr::get($this->data, $key, $default);
     }
     return $this->data;
 }
Example #18
0
 public function save()
 {
     $data = $this->getData();
     unset($data['name']);
     if ($id = $this->getData('id')) {
         $data['id'] = $id;
     }
     if ($new = \Arr::get($data, 'since_new', null)) {
         if ($id) {
             $_date = new \DateTime($new);
             $_date->sub(new \DateInterval('P1D'));
             $close = ['id' => $id];
             $close['till'] = $_date->format('Y-m-d');
             $this->model('ManagerTimeSheet')->upsert($close);
             $id = 0;
             $data['since'] = $new;
             unset($data['id']);
         }
     }
     unset($data['since_new']);
     unset($data['till']);
     if (empty($data['id'])) {
         if (isset($data['id'])) {
             unset($data['id']);
         }
     }
     $_id = $this->model('ManagerTimeSheet')->upsert($data);
     $id = $id ? $id : $_id;
     return $this->model('ManagerTimeSheet')->getById($id);
 }
Example #19
0
 /**
  * Получение access token для авторизации
  * @return bool
  * @throws Kohana_Exception
  */
 private function get_access_token()
 {
     $params = Arr::get($_SERVER, 'QUERY_STRING');
     parse_str($params, $params);
     if (empty($params['code'])) {
         Controller::redirect($this->login_query());
     }
     if (!$params) {
         # TODO: Throw custom Exception for GitHub
         throw new Kohana_Exception('NO QUERY PARAMS');
     }
     if (isset($params['error'])) {
         # TODO: Throw custom Exception for GitHub
         throw new Kohana_Exception('Error: ' . $params['error'] . ' Description: ' . $params['error_description']);
     }
     $params = array('client_id' => self::$config['APP_ID'], 'code' => $params['code'], 'client_secret' => self::$config['APP_SECRET'], 'redirect_uri' => self::$config['REDIRECT_URI']);
     $resp = Request::factory(self::$config['GET_TOKEN_URI'])->method(Request::GET)->query($params)->execute();
     parse_str($resp);
     if (!isset($access_token)) {
         # TODO: Throw custom Exception for GitHub
         throw new Kohana_Exception('Error: ' . $resp->error . ' Description: ' . $resp->error_description);
     }
     $this->token = $access_token;
     //Session::instance()->set('gh_token', $access_token); #TODO: Why is it commented?
     return true;
 }
Example #20
0
 /**
  * Creates a new instance.
  *
  * @param $data New instance data.
  *
  * @return bool
  */
 public function create(array $data)
 {
     $customer_gateway_id = Service_Customer_Gateway::external_id($this->driver->customer, $this->driver->gateway);
     if (!$customer_gateway_id) {
         return false;
     }
     if (!($payment_method = Arr::get($data, 'payment_method'))) {
         return false;
     }
     if (!($amount = Arr::get($data, 'amount'))) {
         return false;
     }
     $request = new AuthorizeNetCIM();
     $transaction = new AuthorizeNetTransaction();
     $transaction->amount = $amount;
     $transaction->customerProfileId = $customer_gateway_id;
     $transaction->customerPaymentProfileId = $payment_method->external_id;
     // AuthOnly or AuthCapture
     $response = $request->createCustomerProfileTransaction('AuthCapture', $transaction);
     if (!$response->isOk()) {
         Log::error('Unable to create Authorize.net transaction.');
         return false;
     }
     $response = $response->getTransactionResponse();
     if (empty($response->transaction_id)) {
         return false;
     }
     return $response->transaction_id;
 }
Example #21
0
 /**
  * 保存账号
  */
 public function action_save()
 {
     $this->_autoRender = FALSE;
     $givenName = Arr::get($_POST, 'given_name', '');
     $name = Arr::get($_POST, 'name', '');
     $password = Arr::get($_POST, 'password', '');
     $email = Arr::get($_POST, 'email', '');
     $mobile = Arr::get($_POST, 'mobile', '');
     $phone = Arr::get($_POST, 'phone', '');
     if ($givenName == '') {
         return Prompt::jsonWarning('姓名不能为空');
     }
     if ($name == '') {
         return Prompt::jsonWarning('用户名不能为空');
     }
     if ($password == '') {
         return Prompt::jsonWarning('密码不能为空');
     }
     if ($email == '') {
         return Prompt::jsonWarning('邮箱不能为空');
     }
     $values = array('given_name' => $givenName, 'name' => $name, 'password' => md5($password), 'email' => $email, 'mobile' => $mobile, 'phone' => $phone);
     try {
         $result = Model::factory('Account')->create($values)->getArray();
         if (!$result[0]) {
             //TODO 日志
             return Prompt::jsonError('添加账号失败');
         }
     } catch (Exception $e) {
         //TODO 日志
         return Prompt::jsonError('添加账号失败');
     }
     //TODO 日志
     return Prompt::jsonSuccess('添加账号成功', URL::site('account/add'));
 }
Example #22
0
 /**
  * Редактирование отзыва
  * @return void
  */
 public function action_edit()
 {
     $review = ORM::factory('review', $this->request->param('id', NULL));
     if (!$review->loaded()) {
         Message::set(Message::ERROR, 'Такой отзыв не найден');
         $this->request->redirect('admin/service/review');
     }
     if ($_POST) {
         try {
             $review->values($_POST, array('text'));
             $review->active = Arr::get($_POST, 'active', 0);
             $review->update();
             Message::set(Message::SUCCESS, 'Отзыв к компании ' . $review->service->name . ' успешно отредактирован');
             $this->request->redirect('admin/service/review');
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     } else {
         $this->values = $review->as_array();
     }
     $this->view = View::factory('backend/review/form')->set('url', 'admin/service/review/edit/' . $review->id)->set('values', $this->values)->set('errors', $this->errors);
     $this->template->title = 'Редактирования отзыва к ' . $review->service->name;
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
 /**
  * Set a value based on an id. Optionally add tags.
  * 
  * @param   string   id 
  * @param   mixed    data 
  * @param   integer  lifetime [Optional]
  * @return  boolean
  */
 public function set($id, $data, $lifetime = NULL)
 {
     if ($lifetime === NULL) {
         $lifetime = time() + Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
     }
     return eaccelerator_put($this->_sanitize_id($id), $data, $lifetime);
 }
Example #24
0
 public function action_delete()
 {
     $district = $this->get_orm_model('district', $this->_base_url);
     $services = $district->services->find_all();
     if ($_POST) {
         if (Arr::get($_POST, 'submit')) {
             $msg = __(Kohana::message('admin', 'district.delete_success'), array(':name' => $district->name));
             $query = DB::update('services')->set(array('district_id' => NULL))->where('district_id', '=', $district->id)->execute();
             $district->content->delete();
             $district->delete();
             if (count($services) > 0) {
                 $msg .= __(Kohana::message('admin', 'metro.delete_success_services'), array(':count' => count($services)));
             }
             Message::set(Message::SUCCESS, $msg);
         }
         $this->request->redirect($this->_base_url);
     }
     $text = __(Kohana::message('admin', 'district.delete_question'), array(':name' => $district->name));
     if (count($services) > 0) {
         $text .= __(Kohana::message('admin', 'metro.delete_question_services'), array(':count' => count($services)));
     }
     $this->template->title = 'Удаление округа "' . $district->name . '"';
     $this->template->bc['#'] = $this->template->title;
     $this->view = View::factory('backend/delete')->set('from_url', $this->_base_url)->set('title', $this->template->title)->set('text', $text);
     $this->template->content = $this->view;
 }
Example #25
0
 public function display()
 {
     //parse image uri
     $preset = $this->uri->segment(2);
     $fileId = $this->uri->segment(3);
     $file = new File($fileId);
     if (!$file->isFileOfUser($this->c_user->id)) {
         return false;
     }
     $imageFile = $file->image->get();
     $updated = (string) $file->image->updated;
     $manipulator = $this->get('core.image.manipulator');
     if ($this->input->post()) {
         $this->cropParamUpdate($file);
         echo 'images/' . $preset . '/' . $fileId . '/' . $imageFile->updated . '?prev=' . $updated;
     } else {
         $path = FCPATH . $file->path . '/' . $file->fullname;
         $output = $manipulator->getImagePreset($path, $preset, $imageFile, Arr::get($_GET, 'prev', null));
         if ($output) {
             $info = getimagesize($output);
             header("Content-Disposition: filename={$output};");
             header("Content-Type: {$info["mime"]}");
             header('Content-Transfer-Encoding: binary');
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
             readfile($output);
         }
     }
 }
Example #26
0
 /**
  * Loads Session and configuration options.
  *
  * @param  array  $config
  */
 public function __construct($config = array())
 {
     $config['salt_pattern'] = Arr::get($config, 'salt_pattern', Kohana::$config->load('visitor')->get('salt_pattern'));
     !is_array($config['salt_pattern']) and $config['salt_pattern'] = preg_split('/,\\s*/', $config['salt_pattern']);
     $this->_config = $config;
     $this->_session = Session::instance();
 }
Example #27
0
 public function before()
 {
     if (!User::current()) {
         $this->redirect('/login');
     }
     $url = str_replace('.', '_', URL::base() . $this->request->uri());
     if (isset($_GET[$url])) {
         unset($_GET[$url]);
     }
     if (isset($_GET[$url . '/'])) {
         unset($_GET[$url . '/']);
     }
     if (Group::current('is_admin') || Group::current('show_all_jobs') && Group::current('allow_finance')) {
         Pager::$counts[] = 2500;
     }
     if (Arr::get($_GET, 'limit') && in_array($_GET['limit'], Pager::$counts)) {
         DB::update('users')->set(array('list_items' => intval($_GET['limit'])))->where('id', '=', User::current('id'))->execute();
         die(json_encode(array('success' => 'true')));
     }
     if (Arr::get($_GET, 'dismiss')) {
         DB::delete('notifications')->where('user_id', '=', User::current('id'))->and_where('id', '=', intval($_GET['dismiss']))->execute();
         die(json_encode(array('success' => 'true')));
     }
     if (!Group::current('allow_assign')) {
         Enums::$statuses[Enums::STATUS_UNALLOC] = 'Not active';
     }
     View::set_global('notifications', DB::select()->from('notifications')->where('user_id', '=', User::current('id'))->order_by('id', 'desc')->execute());
 }
Example #28
0
 /**
  * Factory for loading minion tasks
  *
  * @param  array An array of command line options. It should contain the 'task' key
  * @throws Minion_Exception_InvalidTask
  * @return Minion_Task The Minion task
  */
 public static function factory($options)
 {
     if (($task = Arr::get($options, 'task')) !== NULL) {
         unset($options['task']);
     } else {
         if (($task = Arr::get($options, 0)) !== NULL) {
             // The first positional argument (aka 0) may be the task name
             unset($options[0]);
         } else {
             // If we didn't get a valid task, generate the help
             $task = 'help';
         }
     }
     $class = Minion_Task::convert_task_to_class_name($task);
     if (!class_exists($class)) {
         throw new Minion_Exception_InvalidTask("Task ':task' is not a valid minion task", array(':task' => $class));
     }
     $class = new $class();
     if (!$class instanceof Minion_Task) {
         throw new Minion_Exception_InvalidTask("Task ':task' is not a valid minion task", array(':task' => $class));
     }
     $class->set_options($options);
     // Show the help page for this task if requested
     if (array_key_exists('help', $options)) {
         $class->_method = '_help';
     }
     return $class;
 }
Example #29
0
 public function action_index()
 {
     $message = false;
     $user = false;
     if (Arr::get($_POST, 'hidden') == 'form_sent') {
         if (Auth::instance()->login(Arr::get($_POST, 'username'), Arr::get($_POST, 'password'), Arr::get($_POST, 'remember'))) {
             $user = Auth::instance()->get_user();
             Session::instance()->set('username', $user->name . ' ' . $user->surname)->set('language', $user->language)->set('listsize', $user->listsize);
         }
     }
     if (Auth::instance()->logged_in()) {
         $user = Auth::instance()->get_user();
         Session::instance()->set('username', $user->name . ' ' . $user->surname)->set('language', $user->language)->set('listsize', $user->listsize);
         try {
             $server_config = $user->object->as_array();
             $fb_config = array('type' => 'pdo', 'connection' => array('dsn' => 'firebird:dbname=' . $server_config['config_server'] . ':' . $server_config['config_bdfile'], 'username' => $server_config['config_bduser'], 'password' => $server_config['config_bdpass']));
             Session::instance()->set('fb_config', $fb_config);
             $fb = Database::instance('fb', $fb_config);
             //$fb->connect();
             $this->request->redirect('/admin/');
         } catch (Database_Exception $e) {
             $message = __('error.connection_db');
             Auth::instance()->logout();
         }
     }
     $this->request->response = View::factory('login', array('message' => $message));
 }
Example #30
-1
 public function action_discrepancies()
 {
     if (!Group::current('is_admin')) {
         throw new HTTP_Exception_403('Forbidden');
     }
     $list = Database_Mongo::collection('jobs')->find(array('discrepancies' => array('$nin' => array(NULL, '', 0))));
     $ids = array();
     foreach ($list as $job) {
         $discr = Database_Mongo::collection('discrepancies')->find(array('job_key' => $job['_id']))->sort(array('update_time' => -1))->getNext();
         $fl = true;
         foreach ($discr['data'] as $key => $value) {
             if ($key == 44) {
                 $status = preg_replace('/[^a-z]/i', '', strtolower($value['old_value']));
                 $status2 = preg_replace('/[^a-z]/i', '', strtolower($value['new_value']));
                 $status0 = preg_replace('/[^a-z]/i', '', strtolower(Arr::get($job['data'], $key, '')));
                 if ($status == $status0) {
                     continue;
                 }
                 if ($status == 'tested' && $status2 != 'tested' || $status == 'built' && ($status2 != 'built' && $status2 != 'tested') || $status != $status2 && in_array($status2, array('deferred', 'dirty', 'heldnbn'), true)) {
                     $fl = false;
                     continue;
                 }
             } elseif ($value['old_value'] != Arr::get($job['data'], $key, '')) {
                 $fl = false;
                 continue;
             }
         }
         if ($fl) {
             $ids[] = $job['_id'];
         }
     }
     Database_Mongo::collection('jobs')->update(array('_id' => array('$in' => $ids)), array('$unset' => array('discrepancies' => 1)), array('multiple' => 1));
     header('Content-type: application/json');
     die(json_encode(array('success' => true)));
 }