Ejemplo n.º 1
0
 /** Check the infos about a paper before inserting
  */
 function checkRequest($connectedUser, $file, $fileRequired, &$texts)
 {
     $configTble = new Config();
     $config = $configTble->fetchAll()->current();
     $this->_messages = array();
     // Some tests...
     if (empty($this->title)) {
         $this->_messages[] = $texts->author->missing_title;
     }
     // Check that the topic is not null or blanck
     if (empty($this->topic)) {
         $this->_messages[] = $texts->author->missing_topic;
     }
     // Check the abstract. Loop on the abstract structure, and check that
     // each abstract section is filled if it is mandatory.
     $abstractStruct = new AbstractSection();
     $abstractStruct->select()->order('position ASC');
     $abstractStructRows = $abstractStruct->fetchAll();
     $countWords = 0;
     foreach ($abstractStructRows as $abstractStructRow) {
         if (!isset($this->_abstract[$abstractStructRow->id])) {
             // This section should exist
             $this->_messages[] = $texts->author->missing_abstract_section;
         } else {
             $this->_abstract[$abstractStructRow->id]->content = trim($this->_abstract[$abstractStructRow->id]->content);
             if ($abstractStructRow->mandatory == "Y" and empty($this->_abstract[$abstractStructRow->id]->content)) {
                 $this->_messages[] = $texts->author->abstract_section_empty . ": " . "{author." . $abstractStructRow->section_name . "}";
             }
             // Count the number of words
             $countWords += str_word_count($this->_abstract[$abstractStructRow->id]->content);
         }
     }
     // echo "Nb words = $countWords<br/>";
     if ($countWords > $config->max_abstract_size) {
         $this->_messages[] = $texts->author->abstract_too_long . " ({$countWords} > {$config->max_abstract_size})";
     }
     // Check the authors
     $found = false;
     $nbAuthors = $this->nbAuthors();
     if ($nbAuthors == 0) {
         $this->_messages[] = $texts->author->missing_authors;
     }
     $connUserPresent = false;
     $mailAuthors = array();
     for ($i = 0; $i < $nbAuthors; $i++) {
         $author = $this->getAuthor($i);
         // Do not check the city and zip code for simple authors
         $messages = $author->checkValues($texts, array("address", "city", "zip_code"));
         foreach ($messages as $message) {
             $iplus = $i + 1;
             $this->_messages[] = "(" . $texts->author->author . " {$iplus}) - " . $message;
         }
         $mailAuthors[$author->email] = 1;
         // Check whether this is the connected user
         if ($author->email == $connectedUser->email) {
             $connUserPresent = true;
         }
     }
     // Check that the same author is not reported twice: compare the number of email
     // to the number of authors (who can do better? Find a nice PHP function)
     if (count($mailAuthors) != count($this->_authors)) {
         $this->_messages[] = $texts->author->duplicate_authors;
     }
     // Test: the connected user must be part of the author list
     if (!$connUserPresent) {
         $this->_messages[] = $texts->author->user_mandatory;
     }
     // Test: at least one contact author
     if ($this->_contactAuthor < 0) {
         $this->_messages[] = $texts->author->missing_contact_author;
     }
     // Test: the file is provided (if required)
     if ($fileRequired) {
         if (!is_uploaded_file($file['tmp_name'])) {
             $this->_messages[] = $this->uploadError($file, $texts);
         } else {
             // Check the PDF format (always in lowercase)
             $ext = substr($file['name'], strrpos($file['name'], '.') + 1);
             if (strToLower($ext) != "pdf") {
                 $this->_messages[] = $texts->author->invalid_format . " (extension:{$ext}, format:" . $paper['format'] . ")";
             }
         }
     }
     // There should be no message
     if (count($this->_messages) > 0) {
         return false;
     } else {
         return true;
     }
 }