public function submit($data, $form)
 {
     $automap = Catalogue::create();
     $form->saveInto($automap);
     $automap->ID = $data['ID'];
     $automap->Last_updated = SS_Datetime::now()->format('Y-m-d H:i:s');
     $automap->validate == false ? $id = $automap->write() : ($id = null);
     if ($id !== null) {
         Session::setFormMessage($form->FormName(), $data['Video_title'], 'has been saved to the catalogue. <br><a href="video-profile/' . $id . '">Preview changes</a>', 'success');
         $this->redirect($this->Link() . "edit/{$id}");
     } elseif ($id === null) {
         Session::setFormMessage($form->FormName(), $data['Video_title'], " is already in the catalogue.", 'bad');
         $this->redirect($this->Link());
     } else {
         Session::setFormMessage($form->FormName(), 'Something went wrong.');
     }
 }
 public function addCatalogue()
 {
     $file = Input::get('addImage');
     $destinationPath = 'public/imgCatalogue';
     $ctlg = Catalogue::all();
     $isAdded = FALSE;
     $validInput = TRUE;
     $regex = "/^[a-zA-Z\\'\\-]+( [a-zA-Z\\'\\-]+)*\$/";
     $regexDesc = "/^[a-zA-Z0-9\\'\\-\\.\\,]+( [a-zA-Z0-9\\,\\'\\-\\.]+)*\$/";
     if (!trim(Input::get('addCatalogueName')) == '' && !trim(Input::get('addCatalogueDesc')) == '') {
         $validInput = TRUE;
         if (preg_match($regex, Input::get('addCatalogueName')) && preg_match($regexDesc, Input::get('addCatalogueDesc'))) {
             $validInput = TRUE;
         } else {
             $validInput = FALSE;
         }
     } else {
         $validInput = FALSE;
     }
     foreach ($ctlg as $ctlg) {
         if (strcasecmp($ctlg->strCatalogueCategory, Input::get('addCategory')) == 0 && strcasecmp($ctlg->strCatalogueName, trim(Input::get('addCatalogueName'))) == 0) {
             $isAdded = TRUE;
         }
     }
     if ($validInput) {
         if (!$isAdded) {
             if ($file == '' || $file == null) {
                 $catalogue = Catalogue::create(array('strCatalogueID' => Input::get('addCatalogueID'), 'strCatalogueCategory' => Input::get('addCategory'), 'strCatalogueName' => trim(Input::get('addCatalogueName')), 'strCatalogueDesc' => trim(Input::get('addCatalogueDesc')), 'boolIsActive' => 1));
             } else {
                 $extension = Input::file('addImg')->getClientOriginalExtension();
                 $fileName = $file;
                 Input::file('addImg')->move($destinationPath, $fileName);
                 $catalogue = Catalogue::create(array('strCatalogueID' => Input::get('addCatalogueID'), 'strCatalogueCategory' => Input::get('addCategory'), 'strCatalogueName' => trim(Input::get('addCatalogueName')), 'strCatalogueDesc' => trim(Input::get('addCatalogueDesc')), 'strCatalogueImage' => 'imgCatalogue/' . $fileName, 'boolIsActive' => 1));
             }
             $catalogue->save();
             return Redirect::to('/maintenance/catalogue?success=true');
         } else {
             return Redirect::to('/maintenance/catalogue?success=duplicate');
         }
     } else {
         return Redirect::to('/maintenance/catalogue?input=invalid');
     }
 }
 /**
  * Inject our product catalogue object into the controller
  * 
  * @return ProductCatalogue
  */
 public function getCatalogue()
 {
     return Catalogue::create();
 }
 public static function Create($catalogue)
 {
     Catalogue::create(array('section_id' => $catalogue->section_id, 'name' => $catalogue->name));
 }