示例#1
0
 /**
  * Delete a student by ID
  * @global type $CFG
  * @param type $studentID
  * @return type 
  * TODO make this transaction based so we don't end up with orphan data
  */
 public function delete_student($studentID)
 {
     global $CFG;
     try {
         $conn = new PDO("mysql:host={$CFG->db};dbname={$CFG->schema}", $CFG->dbuser, $CFG->dbuserpass);
     } catch (PDOException $e) {
         die('<data><error>failed connecting to database</error><detail>' . $e->getMessage() . '</detail></data>');
     }
     $returnStr = 'false';
     // Delete student entry
     $query = "DELETE FROM students WHERE ID = :studentID;";
     $stmt = $conn->prepare($query);
     $stmt->bindValue(':studentID', $studentID, PDO::PARAM_INT);
     $stmt->execute() or die('<data><error>delete_student query failed</error><detail>' . $stmt->errorCode() . '</detail></data>');
     if ($stmt->rowCount() > 0) {
         $medialib = new MediaLib();
         if ($medialib->deleteStudentImage($studentID)) {
             $returnStr = 'true';
         } else {
             $returnStr = 'false';
         }
     } else {
         $returnStr = 'false';
     }
     return "<data><status>{$returnStr}</status></data>";
 }
示例#2
0
文件: MediaFile.php 项目: swk/bluebox
 public function prepare_upload($uploadvar = 'upload')
 {
     if (!arr::get($_FILES, 'mediafile', 'name', $uploadvar)) {
         kohana::log('error', 'Attempted to prepare upload without file');
         return 'Please provide a file to upload';
     }
     $uploadedFile = arr::get(arr::rotate($_FILES['mediafile']), $uploadvar);
     switch ($uploadedFile['error']) {
         case UPLOAD_ERR_INI_SIZE:
             return 'File exceeds upload_max_filesize';
         case UPLOAD_ERR_FORM_SIZE:
             return 'File exceeds MAX_FILE_SIZE';
         case UPLOAD_ERR_PARTIAL:
             return 'File was only partially uploaded';
         case UPLOAD_ERR_NO_FILE:
             return 'No file was uploaded';
         case UPLOAD_ERR_NO_TMP_DIR:
             return 'Missing a temporary folder';
         case UPLOAD_ERR_CANT_WRITE:
             return 'Failed to write file to disk';
         case UPLOAD_ERR_EXTENSION:
             return 'Invalid file extension (type)';
         case UPLOAD_ERR_OK:
             if (!$this->get('file')) {
                 $uploadFilename = $uploadedFile['name'];
                 if (Kohana::config('upload.remove_spaces') === TRUE) {
                     $uploadFilename = preg_replace('/\\s+/', '_', $uploadFilename);
                 }
                 $this->set('file', $uploadFilename);
             }
             if ($this->get('path')) {
                 $path = trim($this->get('path'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                 $this->set('path', $path);
             }
             if (!is_file($uploadedFile['tmp_name'])) {
                 kohana::log('error', 'Unable to locate file in temporary storage ' . $uploadedFile['tmp_name']);
                 return 'Unable to upload file';
             }
             if (!($mediainfo = MediaLib::getAudioInfo($uploadedFile['tmp_name']))) {
                 kohana::log('error', 'Unable to determine audio info for tmp upload file "' . $uploadedFile['tmp_name'] . '"');
                 return 'Upload is not a valid audio file or format';
             }
             $this->fromArray($mediainfo);
             if (kohana::config('mediafile.upload_to_rate_folders')) {
                 $rate = $this->get('rates');
                 $path = $this->get('path');
                 if (in_array($rate, kohana::config('mediafile.default_rates')) and !strstr($path, $rate . DIRECTORY_SEPARATOR)) {
                     $path .= $this->get('rates') . DIRECTORY_SEPARATOR;
                     $this->set('path', $path);
                 } else {
                     if ($unknownPath = kohana::config('mediafile.unknown_rate_folder')) {
                         $path .= trim($unknownPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                         $this->set('path', $path);
                     }
                 }
             }
             $directory = $this->filepath();
             if (!$this->get('name') or !$this->get('description')) {
                 $mediafiles = $this->get_resampled();
                 if (!$this->get('name')) {
                     if (isset($mediafiles[0]['name'])) {
                         $this->set('name', $mediafiles[0]['name']);
                     } else {
                         $this->set('name', pathinfo($uploadedFile['name'], PATHINFO_FILENAME));
                     }
                 }
                 if (!$this->get('description')) {
                     if (isset($mediafiles[0]['description'])) {
                         $this->set('description', $mediafiles[0]['description']);
                     }
                 }
             }
             if (!$directory or !filesystem::is_writable($directory) and !filesystem::createDirectory($directory)) {
                 kohana::log('error', 'The configured media dir is not writable, please chmod "' . $directory . '"');
                 return 'Media collection directory is not writable';
             }
             $this->uploaded_file = $uploadedFile;
             break;
         default:
             return 'Upload failed for an unspecified reason';
     }
     return FALSE;
 }
示例#3
0
     include 'lib/MediaLib.php';
     include 'lib/EnumLib.php';
     $medialib = new MediaLib();
     $medialib->displayMediaThumb($_REQUEST['id'], $_REQUEST['getbig'] == 'true');
     break;
 case "downloadmedia":
     include 'lib/MediaLib.php';
     include 'lib/EnumLib.php';
     $outputReturnStr = false;
     $medialib = new MediaLib();
     $medialib->download_raw_media($_REQUEST['id']);
     break;
 case "deletemedia":
     include 'lib/MediaLib.php';
     include 'lib/EnumLib.php';
     $medialib = new MediaLib();
     $returnStr = $medialib->deleteMediaItem($_REQUEST['id']);
     break;
     //////////////////////////////////////////////////////////////
     //
     //Datagrid stuff
     //
     //////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////
 //
 //Datagrid stuff
 //
 //////////////////////////////////////////////////////////////
 case "getgrid":
     include 'lib/EditableGrid.php';
     include 'lib/GridLib.php';