public function importExternalRecipientsFromFileObject()
 {
     if (trim($_FILES['externalmails']['tmp_name'])) {
         include_once "./Services/Utilities/classes/class.ilCSVReader.php";
         $reader = new ilCSVReader();
         $reader->open($_FILES['externalmails']['tmp_name']);
         $data = $reader->getDataArrayFromCSVFile();
         $fields = array_shift($data);
         foreach ($fields as $idx => $field) {
             $fields[$idx] = $this->removeUTF8Bom($field);
         }
         if (!in_array('email', $fields)) {
             $reader->close();
             ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email'), true);
             $this->ctrl->redirect($this, 'codes');
         }
         $existingdata = $this->object->getExternalCodeRecipients();
         $existingcolumns = array();
         if (count($existingdata)) {
             $first = array_shift($existingdata);
             foreach ($first as $key => $value) {
                 array_push($existingcolumns, $key);
             }
         }
         include_once "Services/Utilities/classes/class.ilStr.php";
         $founddata = array();
         foreach ($data as $row) {
             if (count($row) == count($fields)) {
                 $dataset = array();
                 foreach ($fields as $idx => $fieldname) {
                     // #14811
                     $row[$idx] = $this->_convertCharset($row[$idx]);
                     if (count($existingcolumns)) {
                         if (array_key_exists($idx, $existingcolumns)) {
                             $dataset[$fieldname] = $row[$idx];
                         }
                     } else {
                         $dataset[$fieldname] = $row[$idx];
                     }
                 }
                 if (strlen($dataset['email'])) {
                     array_push($founddata, $dataset);
                 }
             }
         }
         $reader->close();
         if (sizeof($founddata)) {
             $this->object->createSurveyCodesForExternalData($founddata);
             ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
         }
     }
     $this->ctrl->redirect($this, 'codes');
 }
예제 #2
0
 public function importCodes()
 {
     include_once './Services/Utilities/classes/class.ilCSVReader.php';
     if ($_FILES["codesfile"]["tmp_name"] != "") {
         $csv = new ilCSVReader();
         $csv->setDelimiter("");
         if ($csv->open($_FILES["codesfile"]["tmp_name"])) {
             $data = $csv->getDataArrayFromCSVFile();
             for ($i = 0; $i < count($data); $i++) {
                 for ($j = 0; $j < count($data[$i]); $j++) {
                     $this->coupon_obj->addCode(ilUtil::stripSlashes($data[$i][$j]), $_GET["coupon_id"]);
                 }
             }
             ilUtil::sendInfo($this->lng->txt("paya_coupon_codes_import_successful"));
             $this->showCodes();
         } else {
             ilUtil::sendInfo($this->lng->txt("paya_coupons_import_error_opening_file"));
             $this->showCodeImport();
         }
     } else {
         ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields"));
         $this->showCodeImport();
     }
     return true;
 }