function globallink_upload_translation_all_form_validate in GlobalLink Connect for Drupal 7.7
File
- ./
globallink_workbench_all_active_submissions.inc, line 820
Code
function globallink_upload_translation_all_form_validate($form, &$form_state) {
if (!empty($_SESSION['globallink_globalLink_arr'])) {
$globallink_arr = unserialize($_SESSION['globallink_globalLink_arr']);
}
else {
$globallink_arr = array();
}
$num_files = count($_FILES['files']['name']);
for ($i = 0; $i < $num_files; $i++) {
$attr = '';
$attr_val = '';
$data = array();
$file = file_save_upload($i, array(
'file_validate_extensions' => array(
'xml',
),
FILE_EXISTS_RENAME,
));
if ($file) {
$file->status = 1;
$xml = file_get_contents($file->uri);
$dom = new DomDocument();
$dom->preserveWhiteSpace = FALSE;
$dom
->loadXML($xml);
$contents = $dom
->getElementsByTagName('content');
foreach ($contents as $content) {
foreach ($content->attributes as $attr_name => $attr_node) {
if ($attr_name == 'nid' || $attr_name == 'bid' || $attr_name == 'fpid' || $attr_name == 'lid' || $attr_name == 'mlid' || $attr_name == 'pid') {
$attr = $attr_name;
$attr_val = $attr_node->value;
}
}
}
$tbl_record = validate_submission($attr, $attr_val);
if (!empty($tbl_record)) {
$data[] = $tbl_record[1];
$form_state['values']['upload_data'][$i]['type'] = $tbl_record[0];
$form_state['values']['upload_data'][$i]['data'] = $tbl_record[1];
$form_state['values']['upload_data'][$i]['file'] = $file;
foreach ($data as $val) {
if ($val->status == GLOBALLINK_STATUS_TRANSLATION_IMPORTED) {
form_set_error('', $file->filename . t(' file can not upload. Translation is already published.'));
}
}
}
else {
drupal_set_message(t($file->filename . ' file is not a part of this submission.'), 'warning');
}
}
else {
form_set_error('translation_file', t('No file was uploaded.'));
}
}
}