Example #1
0
 /**
  * define page title and load template files
  */
 public function index()
 {
     $this->data['title'] = 'Albums';
     $this->data['category'] = Category::row('category_slug', 'playlist');
     if (isset($_POST) && !empty($_POST)) {
         //generate slug
         $slug = Url::generateSafeSlug($_POST['title']);
         $albumArray = array('album_name' => $_POST['title'], 'album_user_id' => Session::get('user_id'), 'album_description' => $_POST['description'], 'album_created' => time());
         $albumArray = Gump::xss_clean($albumArray);
         $albumArray = Gump::sanitize($albumArray);
         $album_id = $this->albumModel->create($albumArray);
         if ($album_id > 0) {
             $checkSlug = $this->albumModel->getColRow('album_slug', $slug);
             if (!is_bool($checkSlug)) {
                 $updateSlug = $this->albumModel->updateId(array('album_slug' => $slug . $album_id), $album_id);
             }
             //UPLOAD ALBUM COVER
             if ($_FILES["image"]["tmp_name"] != '') {
                 //upload file into uploads folder
                 Upload::setName(time());
                 Upload::resizeUpload($_FILES["image"], UPLOAD_PATH, '480px');
                 $update_data = array('album_image' => Upload::getFileName('images'));
                 $this->albumModel->updateId($update_data, $album_id);
             }
             Session::set('success', 'Album Created');
         } else {
             Session::set('error', 'Operation Fails');
         }
     }
     $this->data['albums'] = $this->albumModel->allalbum();
     View::rendertemplate('header', $this->data);
     View::rendertemplate('sidebar', $this->data);
     View::render('album/album.index', $this->data);
     View::rendertemplate('footer', $this->data);
 }