예제 #1
0
 protected function parseAttachments()
 {
     $upload = new Am_Upload(Am_Di::getInstance(), EmailTemplate::ATTACHMENT_FILE_PREFIX);
     $upload->unserialize($this->template['attachments']);
     foreach ($upload->getUploads() as $file) {
         $f = @fopen($file->getFullPath(), 'r');
         if (!$f) {
             trigger_error("Could not open attachment [" . $file->getName() . "] for EmailTemplate#{$this->email_template_id}", E_USER_WARNING);
             continue;
         }
         $this->getMail()->createAttachment($f, $file->getType(), Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $file->getName());
     }
 }
예제 #2
0
 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')));
     }
 }
 protected function cleanup()
 {
     if ($this->dataSource) {
         unset($this->dataSource);
     }
     $uploads = $this->upload->getUploads();
     foreach ($uploads as $file) {
         $file->delete();
     }
     $this->session->unsetAll();
 }
 protected function getUploadIds(Am_Upload $upload)
 {
     $upload_ids = array();
     foreach ($upload->getUploads() as $upload) {
         $upload_ids[] = $upload->pk();
     }
     return $upload_ids;
 }
예제 #5
0
    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;
        }
    }
 public function afterInsert(array &$values, CouponBatch $record)
 {
     switch ($values['_source']) {
         case self::SOURCE_GENERATE:
             $record->generateCoupons((int) $values['_count'], (int) $values['_code_len'], (int) $values['_code_len']);
             break;
         case self::SOURCE_FILE:
             $upload = new Am_Upload($this->getDi());
             $upload->setTemp(3600);
             if (!$upload->processSubmit('file')) {
                 throw new Am_Exception_InputError('File was not uploaded');
             }
             /* @var $file Upload */
             list($file) = $upload->getUploads();
             $f = fopen($file->getFullPath(), 'r');
             while ($row = fgetcsv($f)) {
                 $coupon = $this->getDi()->couponRecord;
                 $coupon->code = $row[0];
                 $coupon->batch_id = $record->pk();
                 try {
                     $coupon->insert();
                 } catch (Exception $e) {
                 }
             }
             fclose($f);
             break;
         default:
             throw new Am_Exception_InternalError(sprintf('Unknown Coupon Code Source [%s]', $values['_source']));
     }
 }