/**
  * Process a new submission
  */
 function processAction()
 {
     if (!$this->config->submissionClosed()) {
         $form_mode = $this->getRequest()->getParam("form_mode");
         if (empty($form_mode)) {
             throw new Zmax_Exception("Invalid action request (Author::process)");
         }
         if ($this->config->two_phases_submission == "N") {
             $upload = true;
         } else {
             $upload = false;
         }
         // Check whether the file has been uploaded
         if (isset($_FILES['paper']['tmp_name']) and file_exists($_FILES['paper']['tmp_name'])) {
             $file = $_FILES['paper'];
         } else {
             $file = array("tmp_name" => "none");
         }
         // Try to insert or update the paper
         $paper = new Paper();
         $data = array("title" => $_POST['title'], "topic" => $_POST['topic'], "nb_authors_in_form" => $_POST['nb_authors_in_form']);
         if ($form_mode == "insert") {
             // Instantiate a new paper. Fill with the post params.
             $paperRow = $paper->createRow();
             $paperRow->setFilterData(true);
             $paperRow->setFromArray($data);
         } else {
             // The paper exists. First: load from the DB
             $id = $this->getRequest()->getParam("id");
             $paperRow = $paper->find($id)->current();
             // Second: update its content from the form post
             $paperRow->updateFromArray($data);
         }
         // Look whether the user asks for an additional author
         if (isset($_REQUEST['addAuthor'])) {
             $this->view->setFile("content", "submit.xml");
             $paperRow->nb_authors_in_form++;
             $this->view->form_mode = $form_mode;
             $this->view->form_submit = $paperRow->form($this->user, $this->view);
             echo $this->view->render("layout");
             return;
         }
         // First, check the content
         $ok = $paperRow->checkRequest($this->user, $file, $upload, $this->zmax_context->texts);
         // Error?
         if (!$ok) {
             // Error reporting
             $this->view->setFile("content", "submit_error.xml");
             $messages = $paperRow->getMessages();
             $this->view->setBlock("content", "ERROR", "ERRORS");
             foreach ($messages as $message) {
                 $this->view->ERROR_MESSAGE = $message;
                 // NB: parsing is done twice because of abstract codes indirection
                 $this->view->assign("message", "ERROR");
                 $this->view->append("ERRORS", "message");
             }
             $this->view->form_mode = $form_mode;
             $this->view->form_submit = $paperRow->form($this->user, $this->view);
         } else {
             // Save the paper
             $paperRow->saveAll();
             // Put in the view
             $paperRow->putInView($this->view);
             // Store the file if any
             if ($upload) {
                 // get the required file in the submission phase (assume there is only one)
                 $requiredFileTbl = new RequiredFile();
                 $requiredFiles = $requiredFileTbl->fetchAll();
                 foreach ($requiredFiles as $requiredFile) {
                     if ($requiredFile->id_phase == Config::SUBMISSION_PHASE and $requiredFile->file_extension == "pdf") {
                         $required = $requiredFile;
                     }
                 }
                 if (!isset($required)) {
                     throw new Zmax_Exception("Unable to determine the file required in submission phase. Stop");
                 }
                 $paperRow->storeFile($required, $file);
             }
             // Get the mail template
             if ($form_mode == "insert") {
                 $mailContent = "ack_submit";
                 $this->view->setFile("content", "ack_submit.xml");
             } else {
                 $mailContent = "ack_edit";
                 $this->view->setFile("content", "ack_edit.xml");
             }
             // Send a mail to ack the submission
             $mail = new Mail(Mail::SOME_USER, $this->texts->mail->subj_new_submission, $this->view->getScriptPaths());
             $mail->setTo($paperRow->emailContact);
             $mail->loadTemplate($this->lang, $mailContent);
             $mail->setFormat(Mail::FORMAT_HTML);
             if ($this->config->mailOnAbstract == "Y") {
                 $mail->setCopyToChair(true);
             }
             $mailView = $mail->getEngine();
             $paperRow->putInView($mailView);
             $this->config->putInView($mailView);
             $mail->send();
         }
     } else {
         // Submission is closed
         $this->view->content = $this->zmax_context->texts->author->abstract_submission_closed;
     }
     // Two instantiation for ref. solving
     $this->view->assign("content", "content");
     echo $this->view->render("layout");
 }