Exemplo n.º 1
0
 public function importSeasons()
 {
     $option = JRequest::getCmd('option');
     $controller = JRequest::getCmd('controller');
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $path = JPATH_ROOT . "/tmp";
     $upload = new Zend_File_Transfer();
     $upload->setDestination($path);
     $upload->addValidator('Extension', false, array("csv"));
     $errors = array();
     $file = "products_seasons";
     $info = $upload->getFileInfo($file);
     if ($upload->isUploaded($file)) {
         if (!$upload->isValid($file)) {
             foreach ($upload->getMessages() as $k => $v) {
                 $errors[$k] = true;
             }
         }
     }
     if ($upload->receive()) {
         $mProduct = new EcwidgatewayModelProducts();
         $mProduct->processSeasonsCsv($path . "/" . $info[$file]["name"]);
         $msg = "Данные импортированы";
     } else {
         $errorMessages = array("Ошибка при загрузке файла");
         foreach ($errors as $k => $v) {
             if (isset($errors[Zend_Validate_File_Extension::FALSE_EXTENSION])) {
                 $errorMessages[] = JText::_("Недопустимое расширение файла");
             }
         }
         $msg = implode("<p>", $errorMessages);
     }
     $link = 'index.php?option=' . $option . '&controller=' . $controller;
     $this->setRedirect($link, $msg);
 }