public static function setValues($fields, $bind_id, $bind_type, $sf_user, $request) { $extra_fields = ExtraFieldsList::getFieldsByType($bind_type, $sf_user, false, array('all' => true)); foreach ($extra_fields as $ef) { //escape view only fields if (in_array($sf_user->getAttribute('users_group_id'), explode(',', $ef['view_only_access']))) { continue; } if (isset($fields[$ef['id']])) { $v = $fields[$ef['id']]; } else { $v = ''; } $v = app::strip_tags($v); if ($ef['type'] == 'file') { $files = $request->getFiles(); if ($extra_fields_files_delete = $request->getParameter('extra_fields_files_delete')) { if (isset($extra_fields_files_delete[$ef['id']])) { if ($a = Doctrine_Core::getTable('Attachments')->find($extra_fields_files_delete[$ef['id']])) { if (is_file($file_path = sfConfig::get('sf_upload_dir') . '/attachments/' . $a->getFile())) { unlink($file_path); } $a->delete(); } } } if ($extra_fields_files = $request->getParameter('extra_fields_files')) { if (isset($extra_fields_files[$ef['id']])) { $v = $extra_fields_files[$ef['id']]; } } if (strlen($files['extra_fields'][$ef['id']]['name']) > 0) { if ($v > 0) { if ($a = Doctrine_Core::getTable('Attachments')->find($v)) { if (is_file($file_path = sfConfig::get('sf_upload_dir') . '/attachments/' . $a->getFile())) { unlink($file_path); } $a->delete(); } } $file = $files['extra_fields'][$ef['id']]; $filename = rand(111111, 999999) . '-' . $file['name']; move_uploaded_file($file['tmp_name'], sfConfig::get('sf_upload_dir') . '/attachments/' . $filename); $a = new Attachments(); $a->setFile($filename); $a->setBindType('extra_fields'); $a->setBindId($ef['id']); $a->save(); $v = $a->getId(); } } elseif ($ef['type'] == 'date_dropdown') { $v = implode('-', $v); } elseif ($ef['type'] == 'date_range') { $v = implode('|', $v); } elseif ($ef['type'] == 'checkbox' and is_array($v)) { $v = implode("\n", $v); } elseif (is_array($v)) { $v = implode(',', $v); } $f = Doctrine_Core::getTable('ExtraFieldsList')->createQuery()->addWhere('bind_id=?', $bind_id)->addWhere('extra_fields_id=?', $ef['id'])->fetchOne(); if ($f) { $f->setValue($v); $f->save(); } else { $f = new ExtraFieldsList(); $f->setBindId($bind_id); $f->setExtraFieldsId($ef['id']); $f->setValue($v); $f->save(); } } }