Пример #1
0
 public function update()
 {
     if ($this->access->allowed('billboards', 'update')) {
         // validation rules
         $input = Validation::factory($this->input->post())->pre_filter('trim', 'name', 'url', 'status')->add_rules('name', 'required')->add_rules('url', 'required')->add_rules('status', 'required');
         // allow the field to be empty
         $valid_url = $this->input->post('url') ? url::real($this->input->post('url')) : true;
         if ($input->validate() && $valid_url) {
             $billboard = orm::factory('billboard', $this->input->post('id'));
             if ($billboard->loaded) {
                 $billboard->name = $this->input->post('name');
                 $billboard->url = trim($this->input->post('url'));
                 $billboard->status = $this->input->post('status');
                 if ($this->input->post('image')) {
                     $image = $billboard->image = $this->input->post('image');
                 }
                 if ($billboard->save()) {
                     $this->notification->add($this->i18n['system.billboard.success'], $billboard->name);
                     // only upload the file if the image has changed.
                     if (isset($image)) {
                         // make sure that the file location exists, if not create it
                         $cms = DOCROOT . 'application/' . SITE . '/media/cms/billboards/' . $billboard->id;
                         if (file::tree($cms)) {
                             if (file_exists(DOCROOT . 'upload/' . $image)) {
                                 //@todo change this so that the uploads folder is not part of the info sent in
                                 if (rename(DOCROOT . 'upload/' . $image, $cms . '/' . $image)) {
                                     $this->notification->add($this->i18n['cms.image.success']);
                                 } else {
                                     $this->notification->add($this->i18n['cms.image.error']);
                                 }
                             } else {
                                 $this->notification->add($this->i18n['cms.image.error']);
                             }
                         } else {
                             $this->notification->add($this->i18n['cms.folder.error']);
                         }
                     }
                 } else {
                     $this->notification->add($this->i18n['system.billboard.error']);
                 }
             } else {
                 $this->notification->add($this->i18n['system.billboard.invalid']);
                 url::redirect(url::area());
             }
         } else {
             if (!$valid_url) {
                 $this->notification->add($this->i18n['filter.url.invalid']);
             }
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         url::failed();
     }
     url::redirect(url::area() . 'edit/' . $this->input->post('id'));
 }
Пример #2
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);
 }
Пример #3
0
 /**
  * This method will do the update processs upon the location, this needs to be mopved into the frmaework
  * @todo to be moved intot he framework, of the hive feramw work
  */
 public function update()
 {
     if ($this->access->allowed('locations', 'update')) {
         $location = orm::factory('location')->find($this->input->post('id'));
         if ($location->loaded) {
             $input = Validation::factory($this->input->post())->pre_filter('trim')->add_rules('name', 'required')->add_rules('status', 'required')->add_rules('group', 'required')->add_rules('latitude', 'required')->add_rules('longitude', 'required')->add_rules('address', 'required');
             if ($input->validate()) {
                 // make sure that name of the location has not been entered with the same name as an exsiting one
                 if ($this->input->post('name') != $location->name) {
                     $existing = orm::factory('location')->where('name', $this->input->post('name'))->where('group', $this->input->post('group'))->find();
                     if ($existing->loaded) {
                         $this->notification->add($this->i18n['system.location.exists'], array($this->input->post('name'), $this->input->post('group')));
                         url::redirect(url::area() . 'edit/' . $location->name);
                         // redirect back to the edit page
                     }
                 }
                 $location->name = $this->input->post('name');
                 $location->description = $this->input->post('description');
                 $location->url = $this->input->post('url');
                 $location->address = $this->input->post('address');
                 $location->latitude = $this->input->post('latitude');
                 $location->longitude = $this->input->post('longitude');
                 $location->status = $this->input->post('status');
                 $location->group = $this->input->post('group');
                 // now add the image.
                 if (is_array($this->input->post('images'))) {
                     $images = $this->input->post('images');
                     $location->image = $images['logo'];
                 }
                 if ($location->save()) {
                     $this->notification->add($this->i18n['system.location.success'], $location->name);
                     // make sure that the file location exists, if not create it
                     $cms = DOCROOT . 'application/' . SITE . '/media/cms/locations/' . $location->id;
                     if (file::tree($cms)) {
                         if (isset($images)) {
                             // add the campaign logo
                             $path = $images['logo'];
                             if (file_exists(DOCROOT . 'upload/' . $path)) {
                                 //@todo change this so that the uploads folder is not part of the info sent in
                                 if (rename(DOCROOT . 'upload/' . $path, $cms . '/' . $path)) {
                                     $this->notification->add($this->i18n['cms.image.success']);
                                 } else {
                                     $this->notification->add($this->i18n['cms.image.error']);
                                 }
                             } else {
                                 $this->notification->add($this->i18n['cms.cover.error']);
                             }
                         }
                     } else {
                         $this->notification->add($this->i18n['cms.folder.error']);
                     }
                     url::redirect(url::area() . 'edit/' . $location->id);
                 } else {
                     $this->notification->add($this->i18n['system.location.failed'], $location->name);
                 }
             } else {
                 foreach ($input->errors() as $key => $value) {
                     $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
                 }
             }
         } else {
             $this->notification->add($this->i18n['system.location.invalid']);
         }
     } else {
         url::failed();
     }
     url::redirect(url::area() . 'edit/' . $this->input->post('id'));
 }
Пример #4
0
 public function update()
 {
     if ($this->access->allowed('magazines', 'update')) {
         // validation rules
         $input = Validation::factory($this->input->post())->pre_filter('trim', 'name', 'description', 'status', 'released')->add_rules('id', 'required')->add_rules('name', 'required')->add_rules('description', 'required')->add_rules('status', 'required')->add_rules('issue', 'required')->add_rules('published', 'required');
         if ($input->validate()) {
             $magazine = orm::factory('magazine', $this->input->post('id'));
             if ($magazine->loaded) {
                 $magazine->name = $this->input->post('name');
                 $magazine->description = $this->input->post('description');
                 $magazine->published = strtotime($this->input->post('published'));
                 $magazine->status = $this->input->post('status');
                 $magazine->issue = $this->input->post('issue');
                 if (is_array($this->input->post('images'))) {
                     $images = $this->input->post('images');
                     $magazine->cover = $images['cover'];
                 }
                 if ($magazine->save()) {
                     $this->notification->add($this->i18n['system.magazines.success'], $magazine->name);
                     // make sure that the file location exists, if not create it
                     $cms = DOCROOT . 'application/' . SITE . '/media/cms/magazines/' . $magazine->id;
                     if (file::tree($cms)) {
                         if (isset($images)) {
                             // add the campaign logo
                             $location = $images['cover'];
                             if (file_exists(DOCROOT . 'upload/' . $location)) {
                                 //@todo change this so that the uploads folder is not part of the info sent in
                                 if (rename(DOCROOT . 'upload/' . $location, $cms . '/' . $location)) {
                                     $this->notification->add($this->i18n['cms.cover.success']);
                                 } else {
                                     $this->notification->add($this->i18n['cms.cover.error']);
                                 }
                             } else {
                                 $this->notification->add($this->i18n['cms.cover.error']);
                             }
                         }
                     } else {
                         $this->notification->add($this->i18n['cms.folder.error']);
                     }
                 } else {
                     $this->notification->add($this->i18n['system.magazines.failed'], $magazine->name);
                 }
             } else {
                 $this->notification->add($this->i18n['system.magazine.invalid']);
                 url::redirect(url::area());
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         url::failed();
     }
     url::redirect(url::area() . 'edit/' . $this->input->post('id'));
 }
Пример #5
0
 public function update()
 {
     if ($this->access->allowed('campaigns', 'update')) {
         // @todo - add the rest of the required vars
         $input = Validation::factory($this->input->post())->pre_filter('trim', 'name', 'description', 'brief', 'background', 'foreground', 'status')->add_rules('name', 'required')->add_rules('description', 'required')->add_rules('brief', 'required')->add_rules('background', 'required')->add_rules('foreground', 'required')->add_rules('status', 'required')->add_rules('id', 'required', 'length[1,32]');
         if ($input->validate()) {
             $campaign = ORM::factory('campaign', $this->input->post('id'));
             if ($campaign->loaded) {
                 // update the information
                 $campaign->name = $this->input->post('name');
                 $campaign->description = $this->input->post('description');
                 $campaign->brief = $this->input->post('brief');
                 $campaign->background = $this->input->post('background');
                 $campaign->foreground = $this->input->post('foreground');
                 $campaign->status = $this->input->post('status');
                 $images = $this->input->post('images');
                 $campaign->logo = isset($images['logo']) ? $images['logo'] : $campaign->logo;
                 $campaign->title = isset($images['title']) ? $images['title'] : $campaign->title;
                 // delete all papers
                 $pivot = orm::factory('campaigns_paper')->where('campaign_id', $campaign->id)->delete_all();
                 if ($campaign->save()) {
                     $this->notification->add($this->i18n['system.campaign.success'], $campaign->name);
                     /**
                      * Edit associated papers 
                      * Via inspiratiomn->update()
                      * @author Matt Scheurich
                      */
                     $papers = $this->input->post('papers');
                     if (is_array($papers)) {
                         $added = 0;
                         // var used to count the number of papers attached to the campaign
                         foreach ($papers as $paper_id) {
                             $paper = orm::factory('paper', $paper_id);
                             if ($paper->loaded) {
                                 $pivot = orm::factory('campaigns_paper');
                                 $pivot->paper_id = $paper_id;
                                 $pivot->campaign_id = $campaign->id;
                                 if ($pivot->save()) {
                                     $added++;
                                 } else {
                                     $this->notification->add($this->i18n['system.paper.error']);
                                 }
                             } else {
                                 $this->notification->add($this->i18n['system.paper.invalid'], $campaign->name);
                             }
                         }
                         if ($added) {
                             $this->notification->add($this->i18n['system.paper.success'], array($added, $campaign->name));
                         }
                     }
                     // add the logo image
                     // make sure that the file location exists, if not create it
                     $cms = DOCROOT . 'application/' . SITE . '/media/cms/campaigns/' . $campaign->id;
                     if (file::tree($cms)) {
                         if (is_array($images)) {
                             foreach ($images as $type => $location) {
                                 // add the campaign logo
                                 $location = $images[$type];
                                 if (file_exists(DOCROOT . 'upload/' . $location)) {
                                     //@todo change this so that the uploads folder is not part of the info sent in
                                     if (rename(DOCROOT . 'upload/' . $location, $cms . '/' . $location)) {
                                         $this->notification->add($this->i18n['cms.' . $type . '.success']);
                                     } else {
                                         $this->notification->add($this->i18n['cms.' . $type . '.error']);
                                     }
                                 } else {
                                     $this->notification->add($this->i18n['cms.' . $type . '.error']);
                                 }
                             }
                         }
                         /**
                          * go through and update any of old posters if they have changed
                          */
                         $files = $this->input->post('files');
                         // note - if the file['edit'] is empty then delete all of the photos.
                         foreach ($campaign->posters as $poster) {
                             $existing[] = $poster->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('poster')->delete_all($diff)) {
                                 $this->notification->add($this->i18n['system.poster.success'], array('deleted', count($diff), $campaign->name));
                             } else {
                                 // @todo - needs its own notification
                                 $this->notification->add($this->i18n['system.poster.error'], $campaign->name);
                             }
                         }
                         // add the new files
                         if (isset($files['add']) && count($files['add'])) {
                             $directory = DOCROOT . 'application/' . SITE . '/media/cms/campaigns/' . $campaign->id . '';
                             if (file::tree($directory)) {
                                 $added = 0;
                                 /// number of photos added
                                 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.
                                             $poster = orm::factory('poster');
                                             $poster->name = $file;
                                             $poster->description = '';
                                             $poster->campaign_id = $campaign->id;
                                             if ($poster->save()) {
                                                 $added++;
                                             } else {
                                                 $this->notification->add($this->i18n['system.poster.error'], $campaign->name);
                                             }
                                         } else {
                                             $this->notification->add($this->i18n['cms.file.error']);
                                         }
                                     } else {
                                         $this->notification->add($this->i18n['cms.file.error']);
                                     }
                                 }
                                 // add notification for the photos
                                 if ($added) {
                                     $this->notification->add($this->i18n['system.poster.success'], array('added', $added, $campaign->name));
                                 }
                             } else {
                                 $this->notification->add($this->i18n['cms.folder.error']);
                             }
                         }
                         url::redirect(url::area() . 'edit/' . $campaign->id);
                     } else {
                         $this->notification->add($this->i18n['cms.folder.error']);
                     }
                     url::redirect(url::area());
                 } else {
                     $this->notification->add($this->i18n['system.campaign.error']);
                 }
             } else {
                 $this->notification->add($this->i18n['system.campaign.invalid']);
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     }
 }
Пример #6
0
 public function update()
 {
     if ($this->access->allowed('news', 'update')) {
         $input = Validation::factory($this->input->post())->pre_filter('trim')->add_rules('id', 'required')->add_rules('name', 'required')->add_rules('description', 'required')->add_rules('status', 'required')->add_rules('group', 'required');
         if ($input->validate()) {
             $news = ORM::factory('news', $this->input->post('id'));
             if ($news->loaded) {
                 // @todo look for an existing article with the same name as the one given, need to think about whether it needs to be by article.
                 $news->name = $this->input->post('name');
                 $news->description = $this->input->post('description');
                 $news->status = $this->input->post('status');
                 $news->group = $this->input->post('group');
                 $image = $this->input->post('image');
                 if (isset($image)) {
                     $magazine->image = $image;
                 }
                 if ($news->save()) {
                     $this->notification->add($this->i18n['system.news.success'], $news->name);
                     // make sure that the file location exists, if not create it
                     $cms = DOCROOT . 'application/' . SITE . '/media/cms/magazines/' . $news->id;
                     if (file::tree($cms)) {
                         if (isset($image)) {
                             // add the campaign logo
                             $location = $image;
                             if (file_exists(DOCROOT . 'upload/' . $location)) {
                                 //@todo change this so that the uploads folder is not part of the info sent in
                                 if (rename(DOCROOT . 'upload/' . $location, $cms . '/' . $location)) {
                                     $this->notification->add($this->i18n['cms.cover.success']);
                                 } else {
                                     $this->notification->add($this->i18n['cms.cover.error']);
                                 }
                             } else {
                                 $this->notification->add($this->i18n['cms.cover.error']);
                             }
                         }
                     } else {
                         $this->notification->add($this->i18n['cms.folder.error']);
                     }
                     url::redirect(url::routes_area() . 'edit/' . $news->id);
                 } else {
                     $this->notification->add($this->i18n['system.news.error']);
                 }
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         Kohana::log('debug', 'User failed method security check');
         url::failed();
     }
 }
Пример #7
0
 public function update()
 {
     if ($this->access->allowed('inspirations', 'update')) {
         // @todo - add the rest of the required vars
         $input = Validation::factory($this->input->post())->pre_filter('trim', 'name', 'description', 'status', 'released', 'printer_url', 'studio_url')->add_rules('name', 'required')->add_rules('description', 'required')->add_rules('status', 'required')->add_rules('application_id', 'required')->add_rules('industry_id', 'required')->add_rules('released', 'required')->add_rules('id', 'required', 'length[1,32]');
         // if the item has not been sent in then it is valid : ie allow empty values as valid.
         $valid_studio_url = $this->input->post('studio_url') ? url::real($this->input->post('studio_url')) : true;
         $valid_printer_url = $this->input->post('printer_url') ? url::real($this->input->post('printer_url')) : true;
         // above the validate in case we need to redirect
         $inspiration = ORM::factory('inspiration', $this->input->post('id'));
         if ($input->validate() && $valid_studio_url && $valid_printer_url) {
             if ($inspiration->loaded) {
                 $inspiration->name = $this->input->post('name');
                 $inspiration->description = $this->input->post('description');
                 $inspiration->application_id = $this->input->post('application_id');
                 $inspiration->studio = $this->input->post('studio');
                 $inspiration->studio_url = trim($this->input->post('studio_url'));
                 $inspiration->printer = $this->input->post('printer');
                 $inspiration->printer_url = trim($this->input->post('printer_url'));
                 $inspiration->status = $this->input->post('status');
                 $inspiration->released = strtotime($this->input->post('released'));
                 $inspiration->industry_id = $this->input->post('industry_id');
                 // delete all inspirationg pigments
                 $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'], $inspiration->name);
                             }
                         }
                         if ($added) {
                             $this->notification->add($this->i18n['system.pigment.success'], $added);
                         }
                     }
                     // 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 {
                             // @todo - needs its own notification
                             $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;
                             /// number of photos added
                             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'], $inspiration->name);
                                         }
                                     } else {
                                         $this->notification->add($this->i18n['cms.file.error']);
                                     }
                                 } else {
                                     $this->notification->add($this->i18n['cms.file.error']);
                                 }
                             }
                             // add notification for the photos
                             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::area() . 'edit/' . $inspiration->id);
                 } else {
                     $this->notification->add($this->i18n['system.inspiration.error']);
                 }
             } else {
                 $this->notification->add($this->i18n['system.inspiration.invalid']);
             }
         } else {
             if (!$valid_studio_url) {
                 $this->notification->add($this->i18n['filter.studio_url.invalid']);
             }
             if (!$valid_printer_url) {
                 $this->notification->add($this->i18n['filter.printer_url.invalid']);
             }
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         url::failed();
     }
     url::redirect(url::area() . 'edit/' . $inspiration->id);
     // name might not exist
 }
Пример #8
0
 public function update()
 {
     if ($this->access->allowed('papers', 'update')) {
         // check the inputs
         $input = Validation::factory($this->input->post())->pre_filter('trim')->add_rules('name', 'required')->add_rules('id', 'required');
         if ($input->validate()) {
             $paper = ORM::factory('paper')->find($this->input->post('id'));
             if ($paper->loaded) {
                 if ($this->input->post('name') != $paper->name) {
                     // check to make sure that the paper they are adding is unique
                     $existing = ORM::factory('paper')->where('name', $this->input->post('name'))->find();
                     if ($existing->loaded) {
                         $this->notification->add($this->i18n['system.paper.exists'], $this->input->post('name'));
                         url::redirect(url::area() . 'edit/' . $paper->name);
                         // redirect back to the edit page
                     }
                 }
                 $paper->colors = $this->input->post('colors') ? $this->input->post('colors') : array();
                 $paper->applications = $this->input->post('applications') ? $this->input->post('applications') : array();
                 $paper->characteristics = $this->input->post('characteristics') ? $this->input->post('characteristics') : array();
                 $paper->environmentals = $this->input->post('environmentals') ? $this->input->post('environmentals') : array();
                 $paper->status = $this->input->post('status');
                 $paper->name = $this->input->post('name');
                 $paper->description = $this->input->post('description');
                 $paper->brief = $this->input->post('brief');
                 $paper->availablity_id = $this->input->post('availablity_id');
                 $paper->price_site = $this->input->post('price_site');
                 $paper->price_style = $this->input->post('price_style');
                 $paper->type = $this->input->post('type');
                 $paper->popular = $this->input->post('popular') == 'true' ? true : false;
                 $paper->style_id = $this->input->post('style_id');
                 $ids = array();
                 if (is_array($this->input->post('features'))) {
                     // loop thorugh each of the features which were added and add them to the paper
                     foreach ($this->input->post('features') as $feature_name) {
                         $feature = orm::factory('feature');
                         $feature = $feature->set($feature_name);
                         $ids[] = $feature->id;
                     }
                 }
                 $ids = array_unique($ids);
                 // delete all the entreis for that paper/feature, then readd them.
                 ORM::factory('features_paper')->where('paper_id', $paper->id)->delete_all();
                 foreach ($ids as $key => $feature_id) {
                     $features_paper = ORM::factory('features_paper');
                     $features_paper->feature_id = $feature_id;
                     $features_paper->paper_id = $paper->id;
                     $features_paper->order = $key;
                     $features_paper->save();
                 }
                 $ids = array();
                 if (is_array($this->input->post('tips'))) {
                     // loop thorugh each of the features which were added and add them to the paper
                     foreach ($this->input->post('tips') as $tip_name) {
                         $tip = orm::factory('tip');
                         $tip = $tip->set($tip_name);
                         $ids[] = $tip->id;
                     }
                 }
                 $ids = array_unique($ids);
                 // delete all the entreis for that paper/feature, then readd them.
                 ORM::factory('papers_tip')->where('paper_id', $paper->id)->delete_all();
                 foreach ($ids as $key => $tip_id) {
                     $papers_tip = ORM::factory('papers_tip');
                     $papers_tip->tip_id = $tip_id;
                     $papers_tip->paper_id = $paper->id;
                     $papers_tip->order = $key;
                     $papers_tip->save();
                 }
                 $images = $this->input->post('images');
                 // check to see if we need to update the images (any of them)
                 if (count($images)) {
                     // make sure that the file location exists, if not create it
                     $cms = DOCROOT . 'application/' . SITE . '/media/cms/products/papers/' . $paper->id;
                     if (file::tree($cms)) {
                         foreach ($images as $type => $location) {
                             $paper->{$type} = $location;
                             if (file_exists(DOCROOT . 'upload/' . $location)) {
                                 //@todo change this so that the uploads folder is not part of the info sent in
                                 if (rename(DOCROOT . 'upload/' . $location, $cms . '/' . $location)) {
                                     $this->notification->add($this->i18n['cms.image.success'], $type);
                                 } else {
                                     $this->notification->add($this->i18n['cms.image.error'], $type);
                                 }
                             } else {
                                 $this->notification->add($this->i18n['cms.image.error'], $type);
                             }
                         }
                     } else {
                         $this->notification->add($this->i18n['cms.folder.error']);
                     }
                 }
                 if ($paper->save()) {
                     $this->notification->add($this->i18n['system.paper.success'], $paper->name);
                 } else {
                     $this->notification->add($this->i18n['system.paper.error'], $paper->name);
                 }
                 url::redirect(url::area() . 'edit/' . url::encode($paper->name));
             } else {
                 $this->notification->add($this->i18n['system.paper.error'], $this->input->post('name'));
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     } else {
         url::failed();
     }
     url::redirect(url::area());
 }