Ejemplo n.º 1
0
 public function view($id, $parity)
 {
     // check to see if the user has access, this is in case we want to make it so that only logged in people can view lightboxes in the future, etc/.
     if ($this->access->allowed('lightboxes', 'read')) {
         $parity_field = 'name';
         // this is a  variable so that it can easily be changed in the future.
         $lightbox = orm::factory('lightbox')->find($id);
         // sanity check and parity check.
         if ($lightbox->loaded && $lightbox->{$parity_field} == url::decode($parity)) {
             // The only times that a lightbox are viewable are when it is public or the current user is the owner. 	A status of approved = public, a status of pending = private
             if ($lightbox->status == 'approved' || $this->user && $this->user->id == $lightbox->creator_id) {
                 $view = new view(url::routes_area() . 'view');
                 // add one to the views for the lightbox.
                 $lightbox->views += 1;
                 $lightbox->save(false);
                 $view->lightbox = $lightbox;
                 $view->is_owner = $this->user && $this->user->id == $lightbox->creator_id;
                 $view->current_user = $this->current;
                 $this->breadcrumbs->add()->url(url::current())->title($lightbox->name);
                 $view->breadcrumbs = $this->breadcrumbs->get();
                 $this->breadcrumbs->delete();
                 $this->template->content = $view;
             } else {
                 $this->notification->add($this->i18n['system.lightbox.status']);
                 url::redirect('account');
             }
         } else {
             $this->notification->add($this->i18n['system.lightbox.invalid']);
             url::redirect('account');
         }
     } else {
         $this->notification->add($this->i18n['system.lightbox.login']);
         url::redirect('account');
     }
 }
Ejemplo n.º 2
0
 /**
  * Used to display the index page but also uses a jquery and the pagination to do preload of next pages
  * of the news articles. Which are then displaye don scroll 
  * @param integer $page the page number  (Matt are you sure this is needed, the pagination is smart enough not to need this). 
  */
 public function index($page = 1)
 {
     $total = orm::factory('news')->where('group', 'site')->where('status', 'approved')->count_all();
     $paging = new Pagination(array('total_items' => $total, 'items_per_page' => 3));
     $articles = orm::factory('news')->where('group', 'site')->where('status', 'approved')->find_all($paging->items_per_page, $paging->sql_offset);
     $view = new View(url::location());
     $view->articles = $articles;
     $view->pagination = $paging->render();
     $view->page_number = $paging->page_number();
     // If the request is an ajax request, then the page is attempting to autoupdate
     // the items with in the news, so just send through the news items.
     if (request::is_ajax()) {
         // if the ajax is attempting to get a page which doesnt exist, send 404
         if ($page > $paging->total_pages) {
             Event::run('system.404');
         } else {
             $this->ajax['view'] = $view;
         }
     } else {
         // otherwise its a http request, send throught he entire page with template.
         $this->template->title = 'About Us › News & Updates Archive';
         $this->breadcrumbs->add()->url(false)->title('Archive');
         $view->breadcrumbs = $this->breadcrumbs->cut();
         $this->template->content = $view;
     }
 }
Ejemplo n.º 3
0
 public function index()
 {
     $view = new View(url::location());
     $view->articles = orm::factory('news')->where('group', 'site')->where('status', 'approved')->find_all(6);
     $this->template->title = 'About Us › News & Updates';
     $this->template->content = $view;
 }
Ejemplo n.º 4
0
 public function index()
 {
     $view = new View(url::location());
     $this->template->title = 'About Us › Global Alliances';
     $view->breadcrumbs = $this->breadcrumbs->cut();
     $view->locations = orm::factory('location')->where('status', 'approved')->where('group', 'alliances')->find_all();
     $this->template->content = $view;
 }
Ejemplo n.º 5
0
 /**
  * Simple delete of the object, plus a call to the unify to check to see if the 
  * collection also needs to be deleted. 
  * @return boolean $return, whether or not  the call did everything expected
  */
 public function delete()
 {
     $original = orm::factory('pigment', $this->id);
     $return = parent::delete();
     if ($return) {
         $return = $this->unify($original);
     }
 }
Ejemplo n.º 6
0
 public function glossary()
 {
     $view = new View(url::location());
     $this->template->title = 'Environmental › Glossary';
     $this->breadcrumbs->add()->url(false)->title('Glossary');
     $view->breadcrumbs = $this->breadcrumbs->cut();
     $view->glossaries = orm::factory('glossary')->where('status', 'approved')->find_all();
     $this->template->content = $view;
 }
Ejemplo n.º 7
0
 /**
  * Simple delete of the object, plus a call to the unify to check to see if the 
  * pigment also needs to be deleted. 
  * @return boolean $return, whether or not  the call did everything expected
  */
 public function delete()
 {
     $original = orm::factory('sheet', $this->id);
     $return = parent::delete();
     // if it was deleted, then verfiy
     if ($return) {
         $return = $this->unify($original);
     }
     return $return;
 }
Ejemplo n.º 8
0
 public function index()
 {
     $this->breadcrumbs->delete();
     $this->template->title = 'Home';
     $view = new view('home/index');
     $view->inspirations = orm::factory('inspiration')->where('status', 'approved')->find_all();
     $view->billboards = orm::factory('billboard')->where('status', 'approved')->find_all();
     $view->populars = orm::factory('paper')->where('status', 'approved')->where('popular', 'true')->orderby(NULL, 'RAND()')->find_all(8);
     $view->news = orm::factory('news')->where('group', 'site')->where('status', 'approved')->find_all(3);
     $this->template->content = $view;
 }
Ejemplo n.º 9
0
 public function set($name)
 {
     $tip = orm::factory('tip')->where('name', $name)->find();
     if ($tip->loaded) {
         return $tip;
     } else {
         $this->name = $name;
         parent::save();
         return $this;
     }
 }
Ejemplo n.º 10
0
 /**
  * This will call the parentxontent controller to populate the view, while sending throught he type of content that it is 
  * as well as the paper_id, which will be used to autocomplete the paper combo box withg the correct result. 
  * @see Content_Controller::add()
  */
 public function add($paper_id = NULL)
 {
     $paper = orm::factory('paper', $paper_id);
     // load the paper so that we can get all the details required to populate the breadrumbs
     if ($paper->loaded) {
         $this->breadcrumbs->add()->url('products/papers/edit/' . url::encode($paper->name))->title(url::decode($paper->name));
         $this->breadcrumbs->add()->url('products/papers/technicals/index/' . $paper->id)->title('Technicals');
         $this->breadcrumbs->add()->url(false)->title('Add');
     }
     parent::add('technical', $paper->id);
 }
Ejemplo n.º 11
0
 public function set($name)
 {
     $feature = orm::factory('feature')->where('name', $name)->find();
     if ($feature->loaded) {
         return $feature;
     } else {
         $this->name = $name;
         parent::save();
         return $this;
     }
 }
Ejemplo n.º 12
0
 /**
  * Create as we need to build the paper name if one doesnt exist. 
  */
 public function get()
 {
     $results = parent::get();
     // we have the results, we now need to go through and build the names up
     for ($i = 0; $i < count($results); $i++) {
         if ($results[$i]['name'] == NULL) {
             $collection = orm::factory('collection')->find($results[$i]['collection_id']);
             $results[$i]['name'] = $collection->paper->name . ' ' . $collection->finish->name . ' ' . ucwords($results[$i]['color']);
         }
     }
     return $results;
 }
Ejemplo n.º 13
0
 public function calculate_total()
 {
     $price = orm::factory('dish', $this->dish_id)->price;
     $temp = $this->get_ingredients_in_order_dish();
     foreach ($temp as $ingred) {
         $price += $ingred->price;
     }
     $temp = $this->get_subs_in_order_dish();
     foreach ($temp as $sub) {
         $price += $sub->price;
     }
     $this->price = $price;
     $this->save();
 }
Ejemplo n.º 14
0
 public function action_add($ordersdish_id, $ingredient_id, $price = NULL)
 {
     $ordersdishesingredient = ORM::factory('ordersdishesingredient');
     $ordersdishesingredient->orders_dishes_id = $ordersdish_id;
     $ordersdishesingredient->ingredient_id = $ingredient_id;
     if (!$price) {
         $dish_id = orm::factory('ordersdish', $ordersdish_id)->dish_id;
         $temp = orm::factory('dishesingredient')->where('dish_id', '=', $dish_id)->and_where('ingredient_id', '=', $ingredient_id)->find();
         $ordersdishesingredient->price = $temp->price;
     } else {
         $ordersdishesingredient->price = $price;
     }
     $ordersdishesingredient->save();
 }
Ejemplo n.º 15
0
 public function action_add($ordersdish_id, $group_id, $sub_id, $price = NULL)
 {
     $ordersdishesgroupssub = ORM::factory('ordersdishesgroupssub');
     $ordersdishesgroupssub->orders_dishes_id = $ordersdish_id;
     $ordersdishesgroupssub->group_id = $group_id;
     $ordersdishesgroupssub->sub_id = $sub_id;
     if (!$price) {
         $sub = orm::factory('sub')->where('group_id', '=', $group_id)->and_where('sub_id', '=', $sub_id)->find();
         $group_price = orm::factory('group', $group_id)->price;
         $ordersdishesgroupssub->price = $sub->price > 0 ? $sub->price : $group_price;
     } else {
         $ordersdishesgroupssub->price = $price;
     }
     $ordersdishesgroupssub->save();
 }
Ejemplo n.º 16
0
 public function __get($name)
 {
     // Are we trying to get the gsms
     if ($name == 'gsms') {
         // if the gsms are not set ... set them and then return
         if (is_null($this->gsms)) {
             $this->gsms = $this->db->select('gsms.name')->from('gsms')->where('collections.paper_id', $this->id)->join('sheets', 'sheets.id', 'gsms.sheet_id')->join('pigments', 'sheets.pigment_id', 'pigments.id')->join('collections', 'collections.id', 'pigments.collection_id')->orderby('gsms.name')->groupby('gsms.name')->get();
         }
         return $this->gsms;
     } elseif ($name == 'technicals') {
         $technicals = orm::factory('technical')->where('foreign_id', $this->id)->where('type', 'technical');
         return $technicals->find_all();
     } else {
         return parent::__get($name);
     }
 }
Ejemplo n.º 17
0
 /** 
  * This page will display a page much like the page for the paper products. 
  * 
  * the expcetion will be it will have multiple images and missing some of the relationships that 
  * the papers have.
  * 
  * 
  * @param unknown_type $name
  */
 public function view($name)
 {
     // clean the input, remove and opf the escape characters
     $name = url::encode($name);
     $industrial = orm::factory('industrial')->where('name', $name)->find_all();
     //if ($industrial->loaded)
     //{
     $view = new view(url::location());
     $view->industrial = $industrial[0];
     $this->template->title = ucwords($name);
     $this->template->content = $view;
     //}
     //else
     //{
     // unable to find the industrial item
     //}
 }
Ejemplo n.º 18
0
 public function index()
 {
     $this->profiler = new Profiler();
     $view = new View(url::location());
     $this->template->title = 'Products';
     $view->breadcrumbs = $this->breadcrumbs->cut();
     // get the differnt types of favourite products.
     $types = array('standard', 'sticky', 'digital');
     /// loop through the three types of papers, assign three popular of that type for each one.
     foreach ($types as $type) {
         $var = $type . '_papers';
         $view->{$var} = orm::factory('paper')->where('type', $type)->where('status', 'approved')->where('popular', 'true')->orderby(NULL, 'RAND()')->find_all(3);
     }
     // get three random popular indsutrial items.
     $view->industrials = orm::factory('industrial')->where('status', 'approved')->where('popular', 'true')->orderby(NULL, 'RAND()')->find_all(3);
     $this->template->content = $view;
 }
Ejemplo n.º 19
0
 public function view($name)
 {
     $name = url::decode($name);
     // check it exists and is published
     $campaign = orm::factory('campaign')->where('name', $name)->where('status', 'approved')->find();
     if ($campaign->loaded) {
         $this->breadcrumbs->add()->url('campaigns')->title('Campaigns');
         $this->breadcrumbs->add()->url(false)->title($campaign->name);
         $this->template->title = 'Campaigns &rsaquo; ' . $campaign->name;
         $view = new view(url::location());
         $view->campaign = $campaign;
         $view->breadcrumbs = $this->breadcrumbs->cut();
         $this->template->content = $view;
     } else {
         $this->notification->add($this->i18n['system.campaign.invalid']);
         url::redirect(url::routes_area());
     }
 }
Ejemplo n.º 20
0
 public function edit($id)
 {
     if ($this->access->allowed('glossaries', 'update')) {
         $glossary = orm::factory('glossary', $id);
         if ($glossary->loaded) {
             $this->breadcrumbs->add()->url(false)->title($glossary->name);
             $view = new view(url::location());
             $view->glossary = $glossary;
             $this->template->title = 'Edit Glossary Article';
             $this->template->content = $view;
         } else {
             // tell the user that the article doesnt exist
             // @todo add notification
             //$this->notification->add();
             url::redirect(url::routes_area());
         }
     } else {
         Kohana::log('debug', 'User failed method security check');
         url::failed();
     }
 }
Ejemplo n.º 21
0
 function action_dishsearch($rest)
 {
     $result = DB::select()->from('dishes')->where('restaurant_id', '=', $rest)->and_where('active', '=', 1);
     if (isset($_POST['dish_name']) and !empty($_POST['dish_name'])) {
         $result->and_where('name', 'LIKE', '%' . $_POST['dish_name'] . '%');
     }
     if (isset($_POST['auto_ingredient']) and !empty($_POST['auto_ingredient'])) {
         $ingredient = orm::factory('ingredient')->where('name', '=', $_POST['auto_ingredient'])->find();
         $temp = clone $result;
         $result = DB::select('dishes.*')->from('dishes_ingredients')->join(array($temp, 'dishes'), 'INNER')->on('dishes.id', '=', 'dishes_ingredients.dish_id')->where('dishes_ingredients.ingredient_id', '=', $ingredient->id);
     }
     if (isset($_POST['max_price']) and $_POST['max_price'] > 0) {
         $result->and_where('dishes.price', '<=', $_POST['max_price']);
     }
     if (isset($_POST['mdv']) and $_POST['mdv'] > 0) {
         $result->and_where('mdv', '=', $_POST['mdv']);
     }
     if (isset($_POST['dish_category']) and $_POST['dish_category'] != 19) {
         $temp = clone $result;
         $result = DB::select('dishes.*', 'categories_dishes.category_id')->from('categories_dishes')->join(array($temp, 'dishes'), 'INNER')->on('categories_dishes.dish_id', '=', 'dishes.id')->where('categories_dishes.category_id', '=', $_POST['dish_category']);
     }
     $dishes = $result->as_object()->execute();
     $this->template->content = View::factory('site/restaurants/dishes/search')->set('post', $_POST)->set('arr_input', ORM::factory('dish')->get_search_info())->set('dishes', $dishes);
     $this->_ajax = TRUE;
 }
Ejemplo n.º 22
0
 /**
  * This little method is used to update the order of the FAQ articles, 
  * it will accept an array of the new order. This has been created 
  * to be used with a drag n drop jquery script. called jquery.hive.resort
  * 
  * @var POST array 
  * 		array(2) {
  * 		  [0]=>
  * 		  array(2) {
  * 		    [0]=>
  * 		    string(1) "3"
  * 		    [1]=>
  * 		    string(1) "0"
  * 		  }
  * 		  [1]=>
  * 		  array(2) {
  * 		    [0]=>
  * 		    string(1) "2"
  * 		    [1]=>
  * 		    string(1) "1"
  *		  }
  * 
  * With first int with the e inner most array being the ID of the item
  * With the second int with in the inner most array being the ORDER
  * 
  */
 function update_order()
 {
     if ($this->access->allowed('billboards', 'update')) {
         $data = $this->input->post('data');
         $successes = 0;
         // simple counter to tell end user how many times it worked.
         foreach ($data as $info) {
             $billboard = orm::factory('billboard', $info[0]);
             // @todo does this require a find()
             $billboard->order = $info[1];
             if ($billboard->save()) {
                 $successes++;
             }
         }
         // add the error messages
         if ($successes == count($data)) {
             $this->notification->add($this->i18n['system.billboard.success']);
         } else {
             $this->notification->add($this->i18n['system.billboard.failed'], count($data) - $successes);
         }
     } else {
         url::failed();
     }
 }
Ejemplo n.º 23
0
 /**
  * get the total number
  *
  * @param Array $query_struct
  * @return Int
  */
 function count($query_struct = array())
 {
     $where = array();
     $like = array();
     $in = array();
     $mail_category = orm::factory('mail_category');
     //where
     if (count($query_struct) > 0) {
         if (isset($query_struct['where'])) {
             foreach ($query_struct['where'] as $key => $value) {
                 $where[$key] = $value;
             }
         }
     }
     //like
     if (count($query_struct) > 0) {
         if (isset($query_struct['like'])) {
             foreach ($query_struct['like'] as $key => $value) {
                 $like[$key] = $value;
             }
         }
     }
     //in
     if (count($query_struct) > 0) {
         if (isset($query_struct['in'])) {
             foreach ($query_struct['in'] as $key => $value) {
                 $in[$key] = $value;
             }
         }
     }
     //WHERE
     if (count($where) > 0) {
         $mail_category->where($where);
     }
     //LIKE
     if (count($like) > 0) {
         $mail_category->like($like);
     }
     //IN
     if (count($in) > 0) {
         $mail_category->in($in);
     }
     $count = $mail_category->count_all();
     return $count;
 }
Ejemplo n.º 24
0
 public function action_createingredient($id = NULL)
 {
     $dishesingredient = ORM::factory('dishesingredient', $id);
     $type = isset($id) ? 'edit' : 'add';
     $this->template->content = View::factory('admin/dishesingredients/add&edit')->set('post', $_POST)->set('dishesingredient', $dishesingredient)->set('type', $type)->set('id', $id)->bind('errors', $errors);
     if ($_POST) {
         $dishesingredient->values($_POST);
         if (!$dishesingredient->basic_optional) {
             $dishesingredient->price = 0;
         }
         if ($type == 'add') {
             //echo 'in the if';
             $dishesingredient->ingredient_id = orm::factory('ingredient')->get_id_by_name($_POST["auto_ingredient"]);
         }
         try {
             $dish = ORM::factory('dish', $dishesingredient->dish_id);
             if (!$dish->has('ingredients', $dishesingredient->ingredient_id) and $type == 'add' and $dishesingredient->ingredient_id > 0 or $type == 'edit') {
                 $dishesingredient->save();
             }
             die;
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors('models');
         }
     }
     $this->_ajax = TRUE;
 }
Ejemplo n.º 25
0
 /**
  * delete an item from the system
  */
 public function delete($id = NULL)
 {
     $group = '';
     if ($this->access->allowed('locations', 'delete')) {
         if ($id != NULL) {
             $location = orm::factory('location')->find($id);
             if ($location->loaded) {
                 $location->status = 'deleted';
                 if ($location->save()) {
                     $this->notification->add($this->i18n['system.location.success'], $location->name);
                 } else {
                     $this->notification->add($this->i18n['system.location.error'], $location->name);
                 }
                 $group = $location->group;
                 // set the group
             } else {
                 $this->notification->add($this->i18n['system.location.invalid']);
             }
         } else {
             $this->notification->add($this->i18n['system.location.invalid']);
         }
     } else {
         url::failed();
     }
     if (!request::is_ajax()) {
         url::redirect(url::routes_area() . 'index/' . $group);
     }
 }
Ejemplo n.º 26
0
 /**
  * Process method for the login form. You might note that there is no notification declared if the
  * user is wrong etc. This is all handled by the security class. We just loop through them.
  */
 public function signin()
 {
     $this->ajax['result'] = false;
     // Validate the form input
     $input = Validation::factory($this->input->post())->pre_filter('trim')->add_rules('password', 'required', 'length[' . $this->config['password.security'] . ',32]')->add_rules('unique', 'required', 'length[5,32]');
     // if they are logging in with an email make sure that it is valid.
     if ($this->config['unique'] == 'email') {
         $input->add_rules('unique', 'required', 'email');
     }
     if ($input->validate()) {
         $this->security = new Security();
         // check the user/pass combo, and then log them in if its correct
         if ($this->security->login($input->unique, $input->password, isset($input->remember))) {
             $user = orm::factory('user')->where($this->config['unique'], $input->unique)->find();
             $this->ajax['result'] = true;
             $this->notification->add($this->i18n['system.login.success'], $user->firstname);
             // If the request is not an ajax request and thy tried to visit a page that required a login, then send them there.
             if (!request::is_ajax()) {
                 if ($this->input->post('redirect')) {
                     url::redirect($this->input->post('redirect'));
                 } else {
                     // send them to the account/index - on login
                     url::redirect(url::area() . 'index');
                 }
             }
         } else {
             foreach ($this->security->notifications as $error) {
                 $this->notification->add($error);
             }
             url::redirect('account/login');
         }
     } else {
         foreach ($input->errors() as $key => $value) {
             if ($key == 'password' && $value == 'length') {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value], $this->config['password.security']);
             } else {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     }
     if (!request::is_ajax()) {
         url::redirect(url::area());
     }
 }
Ejemplo n.º 27
0
 public function create()
 {
     $this->breadcrumbs->add()->url(false)->title('Add Paper');
     // let make sure they are still logged in.
     $current = Security::instance()->get_user();
     // sanity check
     if ($current && $current->loaded) {
         $input = Validation::factory($this->input->post());
         $input->add_rules('paper_id', 'required');
         if ($this->input->post('type') == 'new') {
             $input->add_rules('name', 'required');
         } elseif ($this->input->post('type') == 'existing') {
             $input->add_rules('lightbox_id', 'required');
         }
         $continue = TRUE;
         if ($input->validate()) {
             // sanity checks to make sure that the data is real.
             $lightbox_id = $this->input->post('lightbox_id');
             // check to see if we are ment to be creating a new lightbox
             if ($this->input->post('type') == 'new') {
                 $continue = FALSE;
                 // make sure there are no other lightboxes by this user with the same name
                 $existing = ORM::factory('lightbox')->where('creator_id', $current->id)->where('name', $this->input->post('name'))->find();
                 if ($existing->loaded) {
                     $this->notification->add($this->i18n['system.lightbox.exists'], $this->input->post('name'));
                 } else {
                     // so it is new, create a new one
                     $lightbox = orm::factory('lightbox');
                     $lightbox->name = $this->input->post('name');
                     $lightbox->description = $this->input->post('description');
                     $lightbox->creator_id = $current->id;
                     $lightbox->status = 'public';
                     if ($lightbox->save()) {
                         $lightbox_id = $lightbox->id;
                         $this->notification->add($this->i18n['system.lightbox.success'], $lightbox->name);
                         $continue = TRUE;
                     } else {
                         $this->notification->add($this->i18n['system.lightbox.error']);
                     }
                 }
             }
             $paper = ORM::factory('paper', $this->input->post('paper_id'));
             $lightbox = ORM::factory('lightbox', $lightbox_id);
             if ($continue) {
                 if ($paper->loaded && $lightbox->loaded) {
                     $lightbox->add($paper);
                     if ($lightbox->save()) {
                         $this->notification->add($this->i18n['system.paper.success'], array($paper->name, $lightbox->name));
                     } else {
                         $this->notification->add($this->i18n['system.paper.error'], array($paper->name, $lightbox->name));
                     }
                 } else {
                     if (!$paper->loaded) {
                         $this->notification->add($this->i18n['system.paper.invalid']);
                     }
                     if (!$lightbox->loaded) {
                         $this->notification->add($this->i18n['system.lightbox.invalid']);
                     }
                 }
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         // not logged in
         $this->notification->add($this->i18n['system.user.invalid']);
     }
 }
Ejemplo n.º 28
0
 /**
  * Code to update an inspiration, any attached papers and files.
  */
 public function update()
 {
     // see if they have access - currently disabled, for testing.
     if ($this->access->allowed('inspirations', 'update')) {
         // load the inspiration, make sure the person owns it. Up here for the redirect
         $inspiration = orm::factory('inspiration', $this->input->post('id'));
         // check the filter
         $input = Validation::factory($this->input->post())->pre_filter('trim', 'name', 'description', 'studio', 'printer');
         $input->add_rules('name', 'required', 'length[4,32]');
         $input->add_rules('description', 'required');
         $input->add_rules('industry_id', 'required');
         $input->add_rules('application_id', 'required');
         if ($input->validate()) {
             // sanity : make sure that the id exists etc.
             if ($inspiration && $inspiration->loaded) {
                 // make sure this is their inspiration
                 if ($this->current->id == $inspiration->user_id) {
                     if ($inspiration->status != 'approved') {
                         $inspiration->name = $this->input->post('name');
                         $inspiration->description = $this->input->post('description');
                         $inspiration->studio = $this->input->post('studio');
                         $inspiration->printer = $this->input->post('printer');
                         $inspiration->user_id = $this->current->id;
                         $inspiration->status = 'pending';
                         $inspiration->application_id = $this->input->post('application_id');
                         $inspiration->industry_id = $this->input->post('industry_id');
                         $inspiration->released = strtotime($this->input->post('released'));
                         $pivot = orm::factory('inspirations_pigment')->where('inspiration_id', $inspiration->id)->delete_all();
                         if ($inspiration->save()) {
                             $this->notification->add($this->i18n['system.inspiration.success'], $inspiration->name);
                             $pigments = $this->input->post('pigments');
                             if (is_array($pigments)) {
                                 $added = 0;
                                 // var used to count the number of papers attached to the inspiration
                                 foreach ($pigments as $pigment_id => $description) {
                                     $pigment = orm::factory('pigment', $pigment_id);
                                     if ($pigment->loaded) {
                                         $pivot = orm::factory('inspirations_pigment');
                                         $pivot->pigment_id = $pigment_id;
                                         $pivot->description = $description;
                                         $pivot->inspiration_id = $inspiration->id;
                                         if ($pivot->save()) {
                                             $added++;
                                         } else {
                                             $this->notification->add($this->i18n['system.pigment.error']);
                                         }
                                     } else {
                                         $this->notification->add($this->i18n['system.pigment.invalid']);
                                     }
                                 }
                                 if ($added) {
                                     $this->notification->add($this->i18n['system.pigment.success'], $added);
                                 }
                             }
                             // add the photos
                             // check to see if any of the files have been changed
                             $files = $this->input->post('files');
                             // note - if the file['edit'] is empty then delete all of the photos.
                             foreach ($inspiration->photos as $photo) {
                                 $existing[] = $photo->id;
                             }
                             // check to make sure files edit has been set, if it has not, then set ti to a blank array (for when they delete all of the photos)
                             $files['edit'] = isset($files['edit']) && is_array($files['edit']) ? $files['edit'] : array();
                             $existing = isset($existing) && is_array($existing) ? $existing : array();
                             // find out if the photos they sent in are differnt to the ones that exist
                             $diff = array_diff($existing, $files['edit']);
                             if (is_array($diff) && count($diff) > 0) {
                                 // @todo should prob have differnt notification
                                 if (ORM::factory('photo')->delete_all($diff)) {
                                     $this->notification->add($this->i18n['system.photo.success'], array('deleted', count($diff), $inspiration->name));
                                 } else {
                                     $this->notification->add($this->i18n['system.photo.error'], $inspiration->name);
                                 }
                             }
                             // add the new files
                             if (isset($files['add']) && count($files['add'])) {
                                 $directory = DOCROOT . 'application/' . SITE . '/media/cms/inspirations/' . $inspiration->id . '';
                                 if (file::tree($directory)) {
                                     $added = 0;
                                     foreach ($files['add'] as $file) {
                                         if (file_exists(DOCROOT . 'upload/' . $file)) {
                                             if (rename(DOCROOT . 'upload/' . $file, $directory . '/' . $file)) {
                                                 // the file has been moved, add it to the dbase.
                                                 $photo = orm::factory('photo');
                                                 $photo->name = $file;
                                                 $photo->description = '';
                                                 $photo->inspiration_id = $inspiration->id;
                                                 if ($photo->save()) {
                                                     $added++;
                                                 } else {
                                                     $this->notification->add($this->i18n['system.photo.error']);
                                                 }
                                             } else {
                                                 $this->notification->add($this->i18n['cms.file.error']);
                                             }
                                         } else {
                                             $this->notification->add($this->i18n['cms.file.error']);
                                         }
                                     }
                                     // consolidate the notifications.
                                     if ($added) {
                                         $this->notification->add($this->i18n['system.photo.success'], array('added', $added, $inspiration->name));
                                     }
                                 } else {
                                     $this->notification->add($this->i18n['cms.folder.error']);
                                 }
                             }
                             url::redirect(url::routes_area() . 'edit/' . $inspiration->id);
                         } else {
                             // orm save on the inpiration failed - database.fail
                             $this->notification->add($this->i18n['system.inspiration.failed'], $inspiration->name);
                         }
                     } else {
                         // the inspiration is approved, we cant edit published material
                         $this->notification->add($this->i18n['system.inspiration.approved'], $inspiration->name);
                     }
                 } else {
                     $this->notification->add($this->i18n['system.access.failed']);
                     // access denied, its not their inspiration they are trying to edit.
                 }
             } else {
                 $this->notification->add($this->i18n['system.inspiration.invalid']);
                 // error - no such inspiration exist
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         url::failed();
     }
     url::redirect(url::routes_area() . 'edit/' . $inspiration->id);
 }
Ejemplo n.º 29
0
 /**
  * Page for the ajax searchy for papers
  * @var type string the type of papers to view
  */
 public function search($type = NULL)
 {
     $this->breadcrumbs->add()->url(false)->title('Search');
     $this->template->title = 'Paper Search';
     $view = new View(url::location());
     if (!is_null($type) && in_array($type, array('standard', 'sticky', 'digital'))) {
         $view->type = $type;
     } else {
         $view->type = NULL;
     }
     $view->breadcrumbs = $this->breadcrumbs->cut();
     $view->styles = orm::factory('style')->find_all();
     $view->applications = orm::factory('application')->find_all();
     $view->colors = orm::factory('color')->find_all();
     $view->personalities = orm::factory('personality')->find_all();
     $view->finishes = orm::factory('finish')->find_all();
     // build the gsms array
     $highest = orm::factory('gsm')->orderby('name', 'desc')->find_all(1);
     $lowest = orm::factory('gsm')->orderby('name', 'asc')->find_all(1);
     $lowest = floor($lowest[0]->name / 50) * 50;
     $highest = ceil($highest[0]->name / 50) * 50;
     for ($i = $lowest; $i < $highest; $i = $i + 50) {
         $gsms[] = $i . '-' . ($i + 50);
     }
     $view->gsms = $gsms;
     $this->template->content = $view;
 }
Ejemplo n.º 30
0
 public function action_createsub($group_id)
 {
     $this->_ajax = TRUE;
     $group = ORM::factory('group', $group_id);
     $this->template->content = View::factory('admin/groups/add&edit_sub')->set('post', $_POST)->set('group', $group)->set('type', 'add')->bind('errors', $errors);
     if ($_POST) {
         try {
             $sub_dish = ORM::factory('dish', $_POST['sub_id']);
             if (!$group->has('subs', $sub_dish)) {
                 $group->add('subs', $sub_dish);
                 $sub_in_group = orm::factory('sub')->where('sub_id', '=', $sub_dish->id)->and_where('group_id', '=', $group->id)->find();
                 $sub_in_group->price = $_POST['price'] > 0 ? $_POST['price'] : 0;
                 $sub_in_group->save();
             }
             die;
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors('models');
         }
     }
     $this->_ajax = TRUE;
 }