/** * Parses serialized data of non-primary email addresses * * @param string $value Serialized data in the following format: * email_address1[,invalid_email1[,opt_out1]][;email_address2...] * @param string $fieldTranslated Name of CSV column * * @return array Collection of address properties * @see serializeNonPrimaryEmails() */ protected function parseNonPrimaryEmails($value, $fieldTranslated) { global $mod_strings; $result = array(); if (empty($value)) { return $result; } // explode serialized value into groups of attributes $emails = explode(';', $value); foreach ($emails as $email) { // explode serialized attributes $attrs = explode(',', $email); if (!$attrs) { continue; } $email_address = array_shift($attrs); if (!$this->ifs->email($email_address, array())) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_EMAIL'], $fieldTranslated, $email_address); continue; } $address = array('email_address' => $email_address, 'primary_address' => false, 'invalid_email' => false, 'opt_out' => false); // check if there are elements in $attrs after $email_address was shifted from there if ($attrs) { $invalid_email = array_shift($attrs); $invalid_email = $this->ifs->bool($invalid_email, array()); if ($invalid_email === false) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_BOOL'], $fieldTranslated, $invalid_email); continue; } $address['invalid_email'] = $invalid_email; } // check if there are elements in $attrs after $email_address and $invalid_email were shifted from there if ($attrs) { $opt_out = array_shift($attrs); $opt_out = $this->ifs->bool($opt_out, array()); if ($opt_out === false) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_BOOL'], $fieldTranslated, $opt_out); continue; } $address['opt_out'] = $opt_out; } $result[] = $address; } return $result; }
protected function sanitizeFieldValueByType($rowValue, $fieldDef, $defaultRowValue, $focus, $fieldTranslated) { global $mod_strings, $app_list_strings; switch ($fieldDef['type']) { case 'enum': case 'multienum': if (isset($fieldDef['type']) && $fieldDef['type'] == "multienum") { $returnValue = $this->ifs->multienum($rowValue, $fieldDef); } else { $returnValue = $this->ifs->enum($rowValue, $fieldDef); } // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { if (isset($fieldDef['type']) && $fieldDef['type'] == "multienum") { $returnValue = $this->ifs->multienum($defaultRowValue, $fieldDef); } else { $returnValue = $this->ifs->enum($defaultRowValue, $fieldDef); } } if ($returnValue === FALSE) { $this->importSource->writeError($mod_strings['LBL_ERROR_NOT_IN_ENUM'] . implode(",", $app_list_strings[$fieldDef['options']]), $fieldTranslated, $rowValue); return FALSE; } else { return $returnValue; } break; case 'relate': case 'parent': $returnValue = $this->ifs->relate($rowValue, $fieldDef, $focus, empty($defaultRowValue)); if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $this->ifs->relate($defaultRowValue, $fieldDef, $focus); } // Bug 33623 - Set the id value found from the above method call as an importColumn if ($returnValue !== false) { $this->importColumns[] = $fieldDef['id_name']; } return $rowValue; break; case 'teamset': $this->ifs->teamset($rowValue, $fieldDef, $focus); $this->importColumns[] = 'team_set_id'; $this->importColumns[] = 'team_id'; return $rowValue; break; case 'fullname': return $rowValue; break; default: $fieldtype = $fieldDef['type']; $returnValue = $this->ifs->{$fieldtype}($rowValue, $fieldDef, $focus); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $this->ifs->{$fieldtype}($defaultRowValue, $fieldDef, $focus); } if (!$returnValue) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_' . strtoupper($fieldDef['type'])], $fieldTranslated, $rowValue, $focus); return FALSE; } return $returnValue; } }