/** * Display a form for uploading files * * @return void */ public function ajaxDeleteTask() { // Incoming $id = Request::getInt('asset', 0); if ($id) { $model = new Asset($id); if ($model->exists()) { $model->set('state', 2); if (!$model->store()) { echo json_encode(array('success' => false, 'error' => $model->getError())); return; } } } //echo result echo json_encode(array('success' => true, 'asset' => $id)); }
/** * Store content * Can be passed a boolean to turn off check() method * * @param boolean $check Call check() method? * @return boolean True on success, false if errors */ public function store($check = true) { if (!parent::store($check)) { return false; } if (!$this->get('id')) { if (!$this->_tbl->id) { $this->_tbl->id = $this->_tbl->_db->insertid(); } $this->set('id', $this->_tbl->id); } if ($this->get('_assets')) { $k = 0; foreach ($this->get('_assets') as $i => $asset) { $k++; $a = new Asset($asset['id']); $a->set('type', $asset['type']); $a->set('item_id', $this->get('id')); $a->set('ordering', $k); $a->set('filename', $asset['filename']); if (strtolower($a->get('filename')) == 'http://') { if ($a->get('id') && !$a->remove()) { $this->setError($a->getError()); } } else { if (!$a->store()) { $this->setError($a->getError()); } } } $a->reorder(); } if ($files = $this->get('_files')) { $config = Component::params('com_collections'); // Build the upload path if it doesn't exist $path = $this->filespace() . DS . $this->get('id'); if (!is_dir($path)) { if (!Filesystem::makeDirectory($path)) { $this->setError(Lang::txt('Error uploading. Unable to create path.')); return false; } } $descriptions = $this->get('_descriptions', array()); if (isset($files['name'])) { foreach ($files['name'] as $i => $file) { // Make the filename safe $files['name'][$i] = urldecode($files['name'][$i]); $files['name'][$i] = Filesystem::clean($files['name'][$i]); $files['name'][$i] = str_replace(' ', '_', $files['name'][$i]); // Upload new files if (!Filesystem::upload($files['tmp_name'][$i], $path . DS . $files['name'][$i])) { $this->setError(Lang::txt('ERROR_UPLOADING') . ': ' . $files['name'][$i]); } else { $asset = new Asset(); //$asset->set('_file', $file); $asset->set('item_id', $this->get('id')); $asset->set('filename', $files['name'][$i]); $asset->set('description', isset($descriptions[$i]) ? $descriptions[$i] : ''); if (!$asset->store()) { $this->setError($asset->getError()); } } } } if ($this->getError()) { return false; } } $trashed = $this->assets(array('state' => self::APP_STATE_DELETED)); if ($trashed->total() > 0) { foreach ($trashed as $trash) { if ($trash->get('filename') == 'http://') { $trash->remove(); } } } // Process tags if ($this->get('_tags', null) !== null) { $this->tag($this->get('_tags', ''), $this->get('created_by')); } return true; }