public function uploadAction() { if (!$this->getDi()->uploadAcl->checkPermission($this->getParam('prefix'), Am_Upload_Acl::ACCESS_WRITE, $this->getDi()->auth->getUser())) { throw new Am_Exception_AccessDenied(); } $secure = $this->getParam('secure', false); $upload = new Am_Upload($this->getDi()); $upload->setPrefix($this->getParam('prefix')); $upload->loadFromStored(); $ids_before = $this->getUploadIds($upload); $upload->processSubmit('upload', false); //find currently uploaded file $x = array_diff($this->getUploadIds($upload), $ids_before); $upload_id = array_pop($x); try { $upload = $this->getDi()->uploadTable->load($upload_id); $data = array('ok' => true, 'name' => $upload->getName(), 'size_readable' => $upload->getSizeReadable(), 'upload_id' => $secure ? Am_Form_Element_Upload::signValue($upload->pk()) : $upload->pk(), 'mime' => $upload->mime); echo $this->getJson($data); } catch (Am_Exception $e) { echo $this->getJson(array('ok' => false, 'error' => ___('No files uploaded'))); } }
public function init() { if (!$this->getDi()->uploadAcl->checkPermission('import', Am_Upload_Acl::ACCESS_WRITE, $this->getDi()->authAdmin->getUser())) { throw new Am_Exception_AccessDenied(); } $this->session = new Zend_Session_Namespace('amember_import'); $this->log = Import_Log::getInstance(); $this->upload = new Am_Upload($this->getDi()); $this->upload->setPrefix('import')->setTemp(3600); if ($this->session->path) { $this->dataSource = new Import_DataSource($this->session->path); if (isset($this->session->importOptions['delim'])) { $this->dataSource->setDelim($this->session->importOptions['delim']); } } $this->addImportFields(); }
public function run() { $form = $this->grid->getForm(); $form->setAttribute('target', '_top'); $upload = new Am_Upload(Am_Di::getInstance()); $upload->setPrefix($this->grid->getCompleteRequest()->getParam('prefix')); $upload->loadFromStored(); $ids_before = $this->getUploadIds($upload); if ($form->isSubmitted() && $upload->processSubmit('upload')) { //find currently uploaded file $upload_id = array_pop(array_diff($this->getUploadIds($upload), $ids_before)); $upload = Am_Di::getInstance()->uploadTable->load($upload_id); $upload->desc = $this->grid->getCompleteRequest()->getParam('desc'); $upload->save(); return $this->grid->redirectBack(); } echo $this->renderTitle(); echo $form; }
protected function updateValue() { $name = $this->getName(); //proceess upload only once fo each name static $executed = array(); if (!isset($executed[$name])) { $executed[$name] = 1; $name = $this->getName(); $upload = new Am_Upload(Am_Di::getInstance()); $upload->setPrefix($this->prefix); $upload->loadFromStored(); $ids_before = $this->getUploadIds($upload); $upload->processSubmit($name); //find currently uploaded file $x = array_diff($this->getUploadIds($upload), $ids_before); $upload_id = array_pop($x); if ($upload_id) { $this->upload_id = $upload_id; } } $value = null; foreach ($this->getDataSources() as $ds) { if (null !== ($value = $ds->getValue($name))) { break; } } if (empty($this->attributes['multiple'])) { $value = $this->upload_id ? $this->upload_id : $value; } else { if ($value) { $value = $this->upload_id ? array_merge($value, array($this->upload_id)) : $value; } else { $value = $this->upload_id ? array($this->upload_id) : null; } } $this->setValue($value); }
function run() { $errors = array(); $importFields = array('email' => 'email', 'name_f' => 'name_f', 'name_l' => 'name_l'); $subusers_fields = $this->getDi()->config->get('subusers_fields', array()); /* if (in_array('login', $subusers_fields)) { $importFields['login'] = '******'; } if (in_array('pass', $subusers_fields)) { $importFields['pass'] = '******'; }*/ foreach ($this->getDi()->config->get('subusers_fields', array()) as $field) { $importFields[$field] = $field; } $form = new Am_Form(); $form->setAttribute('target', '_top'); $form->setAttribute('enctype', 'multipart/form-data'); $form->addStatic()->setContent('<div>' . ___('File should contain CSV list of user records for import in the following format:<br /> <strong>%s</strong>', implode(',', $importFields)) . '</div>'); $form->addFile('file[]', null, array('prefix' => self::UPLOAD_PREFIX))->setLabel(___('File'))->addRule('required', ___('This field is a requried field')); $options = $this->getDi()->subusersSubscriptionTable->getProductOptions($this->reseller, true); reset($options); if (count($options) == 1) { $form->addHidden('groups[0]')->setValue(key($options))->toggleFrozen(true); } else { $form->addMagicSelect('groups')->setLabel(___('Groups'))->loadOptions($options); } $form->addSaveButton(___('Do Import')); $this->initForm($form); if ($form->isSubmitted()) { $value = $form->getValue(); $upload = new Am_Upload($this->getDi()); $upload->setPrefix(self::UPLOAD_PREFIX)->setTemp(3600); $upload->processSubmit('file'); list($file) = $upload->getUploads(); if (!$file) { throw new Am_Exception_InputError(___('CSV File was not specified')); } $pn = fopen($file->getFullPath(), 'r'); while ($res = fgetcsv($pn)) { if (count($res) == count($importFields)) { $imp = array(); foreach ($importFields as $fieldName => $v) { $imp[$fieldName] = trim(array_shift($res)); } $user = Am_Di::getInstance()->userRecord; if ($error = $this->checkUniqEmail($imp['email'])) { $errors[] = $error; continue; } if (isset($imp['login']) && ($error = $this->checkUniqLogin($imp['login']))) { $errors[] = $error; continue; } $user->email = $imp['email']; $user->name_f = $imp['name_f']; $user->name_l = $imp['name_l']; isset($imp['pass']) ? $user->setPass($imp['pass']) : $user->generatePassword(); isset($imp['login']) ? $user->login = $imp['login'] : $user->generateLogin(); foreach (array('login', 'email', 'pass', 'name_f', 'name_l') as $k) { unset($imp[$k]); } foreach ($imp as $k => $v) { $user->set($k, $v); } $user->data()->set('signup_email_sent', 1); $user->set('subusers_parent_id', $this->reseller->pk()); $user->is_approved = 1; $user->save(); if ($et = Am_Mail_Template::load('subusers.registration_mail', $user->lang)) { $et->setUser($user); $et->setPassword($user->getPlaintextPass()); $et->setReseller($this->reseller); //backward compatibality (reseller_name_f, reseller_name_l, reseller_email) $et->setReseller_name_f($this->reseller->name_f); $et->setReseller_name_l($this->reseller->name_l); $et->setReseller_email($this->reseller->email); if (!empty($value['groups'])) { $userTitle = array(); foreach ($this->getDi()->productTable->loadIds($value['groups']) as $product) { $userTitle[] = $product->title; } $et->setUser_product(join(', ', $userTitle)); $resellerTitle = array(); $conditions = array('subusers_product_id' => $value['groups']); foreach ($this->getDi()->productTable->findBy($conditions) as $product) { $resellerTitle[] = $product->title; } $et->setReseller_product(join(', ', $resellerTitle)); } $et->send($user); } $this->getDi()->subusersSubscriptionTable->setForUser($user->pk(), $value['groups']); } } fclose($pn); $this->getDi()->modules->get('subusers')->checkAndUpdate($this->reseller); if ($errors) { $out = '<ul class="errors">'; foreach ($errors as $error) { $out .= sprintf('<li>%s</li>', $error); } $out .= "</ul>"; echo $out . $this->renderBackUrl() . '<br /><br />'; } else { $this->grid->redirectBack(); } } else { echo $this->renderTitle(); echo $form; } }