src/Service/excelService.php
public function importCSV ($objName)
    {
        // read in file from $_FILE
        foreach ($_FILES as $file)
        {
            $error = $file['error'];
            if ($error != 0)
            {
                $this->reportError($error);
                return;
            }

            $tmpFileName  = $file['tmp_name'];
            break;
        }
        //echo "upload file name = $tmpFileName";
        $filename = $file['name'];
        if (strpos($filename,".csv")===false)
        {
        	$errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_FILE",array($filename));
        	Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = ".$errorMsg);
            Openbizx::$app->getClientProxy()->showClientAlert($errorMsg);
            return;
        }
        /* @var $formObj EasyForm */
        $formObj = Openbizx::getObject($objName); // get the existing EasyForm object
        $parentFormObj = Openbizx::getObject($formObj->parentFormName);
        $dataObj = $parentFormObj->getDataObj();

        $handle = fopen($tmpFileName, "r");
        $fields = fgetcsv($handle, 2000, ",");
        if (!$fields || count($fields)<2)
        {
        	$errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_FILE",array($filename));
        	Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = ".$errorMsg);
            Openbizx::$app->getClientProxy()->showClientAlert($errorMsg);
            return;
        }

        // convert form element names to DO field names
        foreach ($parentFormObj->dataPanel as $element)
        {
            $elem_fields[$element->label] = $element->fieldName;
        }
        
        // validate with dataobj fields
        for ($i=0; $i<count($fields); $i++)
        {
            $fields[$i] = $elem_fields[$fields[$i]];
            $field = $fields[$i];
            if (!$dataObj->getField($field))
            {
                $errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_COLUMN",array($field, $dataObj->objectName));
                Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = ".$errorMsg);
                Openbizx::$app->getClientProxy()->showClientAlert($errorMsg);
                return;
            }
        }

        while (($arr = fgetcsv($handle, 2000, ",")) !== FALSE)
        {
            if (count($arr) != count($fields))
                continue;
            unset($recArr);
            $i = 0;
            for ($i=0; $i<count($arr); $i++)
            {
                $recArr[$fields[$i]] = $arr[$i];
            }
            //print_r($recArr); echo "<hr>";

            $dataRec = new DataRecord(null, $dataObj);
            foreach ($recArr as $k => $v)
                $dataRec[$k] = $v;

            $ok = $dataRec->save();
            if (! $ok)
            {
                // NOTE: EasyForm::processDataObjError() not return any value (void)
                return $formObj->processDataObjError($ok);
            }

        }
        fclose($handle);

        // in case of popup form, close it, then rerender the parent form
        if ($formObj->parentFormName)
        {
            $formObj->close();

            $formObj->renderParent();
        }
    }
public function importCSV ($objName)
    {
        // read in file from $_FILE
        foreach ($_FILES as $file)
        {
            $error = $file['error'];
            if ($error != 0)
            {
                $this->reportError($error);
                return;
            }

            $tmpFileName  = $file['tmp_name'];
            break;
        }
        //echo "upload file name = $tmpFileName";
        $filename = $file['name'];
        if (strpos($filename,".csv")===false)
        {
        	$errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_FILE",array($filename));
        	Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = ".$errorMsg);
            Openbizx::$app->getClientProxy()->showClientAlert($errorMsg);
            return;
        }
        /* @var $formObj EasyForm */
        $formObj = Openbizx::getObject($objName); // get the existing EasyForm object
        $parentFormObj = Openbizx::getObject($formObj->parentFormName);
        $dataObj = $parentFormObj->getDataObj();

        $handle = fopen($tmpFileName, "r");
        $fields = fgetcsv($handle, 2000, ",");
        if (!$fields || count($fields)<2)
        {
        	$errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_FILE",array($filename));
        	Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = ".$errorMsg);
            Openbizx::$app->getClientProxy()->showClientAlert($errorMsg);
            return;
        }

        // convert form element names to DO field names
        foreach ($parentFormObj->dataPanel as $element)
        {
            $elem_fields[$element->label] = $element->fieldName;
        }
        
        // validate with dataobj fields
        for ($i=0; $i<count($fields); $i++)
        {
            $fields[$i] = $elem_fields[$fields[$i]];
            $field = $fields[$i];
            if (!$dataObj->getField($field))
            {
                $errorMsg = MessageHelper::getMessage("EXCELSVC_INVALID_COLUMN",array($field, $dataObj->objectName));
                Openbizx::$app->getLog()->log(LOG_ERR, "EXCEL SERVICE", "Import error = ".$errorMsg);
                Openbizx::$app->getClientProxy()->showClientAlert($errorMsg);
                return;
            }
        }

        while (($arr = fgetcsv($handle, 2000, ",")) !== FALSE)
        {
            if (count($arr) != count($fields))
                continue;
            unset($recArr);
            $i = 0;
            for ($i=0; $i<count($arr); $i++)
            {
                $recArr[$fields[$i]] = $arr[$i];
            }
            //print_r($recArr); echo "<hr>";

            $dataRec = new DataRecord(null, $dataObj);
            foreach ($recArr as $k => $v)
                $dataRec[$k] = $v;

            $ok = $dataRec->save();
            if (! $ok)
            {
                // NOTE: EasyForm::processDataObjError() not return any value (void)
                return $formObj->processDataObjError($ok);
            }

        }
        fclose($handle);

        // in case of popup form, close it, then rerender the parent form
        if ($formObj->parentFormName)
        {
            $formObj->close();

            $formObj->renderParent();
        }
    }
Import from CSV file
NOTE: This method must be called from a popup form where a file is uploaded.
The parent form of the popup form is the target to import.

@param string $objName
@return void