function DeleteAll($module, $item) { // Delete all paths for a specific item $where = array('module = ' . $module, 'item = ' . $item); if (Database::DeleteFrom('_paths', $where)) { return true; } else { trigger_error("Couldn't delete paths", E_USER_WARNING); } }
function AddUploadedFile($field) { global $_JAM; $tempFilename = $_FILES[$field]['tmp_name']; $this->originalFilenames[$field] = $_FILES[$field]['name']; $fileType = $_FILES[$field]['type']; // If we lack a filetype, try to use GetID3 to figure it out if (!$filetype) { $getID3 = new getID3(); if ($fileInfo = $getID3->analyze($tempFilename)) { $fileType = $fileInfo['mime_type'] ? $fileInfo['mime_type'] : ''; } } // Make sure this is a legitimate PHP file upload if (!is_uploaded_file($tempFilename)) { trigger_error("There is no legitimate uploaded file", E_USER_ERROR); return false; } // Insert into files table $params = array('filename' => $this->originalFilenames[$field], 'type' => $fileType); if (!Database::Insert('files', $params)) { trigger_error("Couldn't insert file into database", E_USER_ERROR); } // Get just-inserted ID of file in files table $fileID = Database::GetLastInsertID(); // Files are named with their ID $destinationFile = $_JAM->filesDirectory . $fileID; // Move file to destination directory if (!move_uploaded_file($tempFilename, $destinationFile)) { // Move failed if (!Database::DeleteFrom('files', 'id = ' . $fileID)) { trigger_error("Couldn't delete database entry for nonexistent file", E_USER_ERROR); } trigger_error("Couldn't move temporary file to files directory", E_USER_ERROR); return false; } // Delete previous item if applicable $previousFileID = $this->parentModule->postData[$field]; if (!$this->parentModule->config['keepVersions'] && $previousFileID) { $this->DeleteItem($previousFileID); } return $fileID; }
function DeleteItem($master) { // First make sure we have sufficient privileges if (!$this->CanDelete()) { trigger_error("Insufficient privileges to delete from module " . $this->name, E_USER_ERROR); return false; } // Delete item if ($this->config['keepVersions']) { $where = 'id = ' . $master . ' OR master = ' . $master; } else { $where = 'id = ' . $master; } if (Database::DeleteFrom($this->name, $where)) { // Delete was successful; get rid of this item in _paths table if (Path::DeleteAll($this->moduleID, $master)) { return true; } else { trigger_error("Couldn't delete paths associated with deleted item", E_USER_ERROR); return false; } // Eventually, delete from _relationships where frommodule = this module } else { if (Database::GetErrorNumber() == 1451) { return ERROR_FOREIGN_KEY_CONSTRAINT; } else { trigger_error("Couldn't delete module item from database", E_USER_ERROR); return false; } } }