public function executeUpload(sfWebRequest $request) { $file = $request->getFiles(); $filename = mt_rand(111111, 999999) . '-' . $file['Filedata']['name']; if (move_uploaded_file($file['Filedata']['tmp_name'], sfConfig::get('sf_upload_dir') . '/attachments/' . $filename)) { $bind_id = $request->getParameter('bind_id'); if ((int) $bind_id == 0) { $bind_id = -$this->getUser()->getAttribute('id'); } $a = new Attachments(); $a->setFile($filename); $a->setBindType($request->getParameter('bind_type')); $a->setBindId($bind_id); $a->save(); } exit; }
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(); } } }
public function executeCopyAttachments(sfWebRequest $request) { if (count($attachments_ids = explode(',', $request->getParameter('attachments'))) > 0) { $attachments = Doctrine_Core::getTable('Attachments')->createQuery()->whereIn('id', $attachments_ids)->execute(); foreach ($attachments as $a) { if (Doctrine_Core::getTable('Attachments')->createQuery()->addWhere('SUBSTRING(file,8)=?', substr($a->getFile(), 7))->addWhere('bind_type=?', $request->getParameter('to'))->addWhere('bind_id=?', -$this->getUser()->getAttribute('id'))->count() == 0) { $new_filename = rand(111111, 999999) . '-' . substr($a->getFile(), 7); copy(sfConfig::get('sf_upload_dir') . '/attachments/' . $a->getFile(), sfConfig::get('sf_upload_dir') . '/attachments/' . $new_filename); $aa = new Attachments(); $aa->setFile($new_filename); $aa->setInfo($a->getInfo()); $aa->setBindType($request->getParameter('to')); $aa->setBindId(-$this->getUser()->getAttribute('id')); $aa->save(); } } } exit; }