Ejemplo n.º 1
0
 /**
  * The on_submit event handles all file uploads immediately. They are passed through
  * the type at that point. This is required, since we do not have persistent upload
  * file management on the QF side. Deletions take precedence over uploads.
  */
 function on_submit($results)
 {
     // TODO: refactor these checks to separate methods
     if (array_key_exists("{$this->name}_delete", $results)) {
         if (!$this->_type->delete_all_attachments()) {
             debug_add("Failed to delete all attached old images on the field {$this->name}.", MIDCOM_LOG_ERROR);
         }
         // Adapt the form:
         $this->_cast_formgroup_to_upload();
     } else {
         if (array_key_exists("{$this->name}_rotate", $results)) {
             // The direction is the key (since the value is the point clicked on the image input)
             list($direction, $dummy) = each($results["{$this->name}_rotate"]);
             if (!$this->_type->rotate($direction)) {
                 debug_add("Failed to rotate image on the field {$this->name}.", MIDCOM_LOG_ERROR);
             }
         } else {
             if ($this->_upload_element->isUploadedFile()) {
                 $file = $this->_upload_element->getValue();
                 if ($this->show_title) {
                     $title = $results["{$this->name}_title"];
                 } else {
                     $title = '';
                 }
                 if (!$this->_type->set_image($file['name'], $file['tmp_name'], $title)) {
                     debug_add("Failed to process image {$this->name}.", MIDCOM_LOG_INFO);
                     $this->_cast_formgroup_to_upload();
                 } else {
                     $this->_cast_formgroup_to_replacedelete();
                 }
             }
         }
     }
 }