/** * Receive the file from the client (Upload) * * @param string|array $files (Optional) Files to receive * @return bool */ public function receive($files = null) { if (!$this->isValid($files)) { return false; } $check = $this->_getFiles($files); foreach ($check as $file => $content) { if (!$content['received']) { $table = $this->getTable(); if ($table === null) { throw new Exception('No table to save set.'); } $filename = $content['name']; $rename = $this->getFilter('Rename'); if ($rename !== null) { $tmp = $rename->getNewName($content['tmp_name']); if ($tmp != $content['tmp_name']) { $filename = $tmp; } $key = array_search(get_class($rename), $this->_files[$file]['filters']); unset($this->_files[$file]['filters'][$key]); } $filecontent = file_get_contents($content['tmp_name']); $filesize = filesize($content['tmp_name']); $filemime = Sendlove_Utilities::getMimeType($content['name']); $filewidth = $fileheight = 0; if (strpos($filemime, 'image') !== false) { list($filewidth, $fileheight) = getimagesize($content['tmp_name']); } $options = array('app' => $this->getApp(), 'content' => $filecontent, 'content_type' => $filemime, 'filename' => Sendlove_Utilities::createUniqueFilename($filename), 'original_filename' => $filename, 'width' => $filewidth, 'height' => $fileheight, 'size' => $filesize, 'created' => new Zend_Db_Expr('NOW()'), 'updated' => new Zend_Db_Expr('NOW()')); if (isset($content['id'])) { $options['id'] = $content['id']; } if (!($fileid = $this->writeToDatabase($options))) { if ($content['options']['ignoreNoFile']) { $this->_files[$file]['received'] = true; $this->_files[$file]['filtered'] = true; continue; } $this->_files[$file]['received'] = false; return false; } $this->_files[$file]['id'] = isset($content['id']) ? $content['id'] : $fileid; } if (!$content['filtered']) { if (!$this->_filter($file)) { $this->_files[$file]['filtered'] = false; return false; } $this->_files[$file]['filtered'] = true; } } return true; }
public function addAction($email = null) { $this->_helper->viewRenderer->setNoRender(true); $validator = new Zend_Validate_EmailAddress(); if ($validator->isValid($this->getRequest()->getParam('email'))) { $splitEmail = explode('@', $this->getRequest()->getParam('email')); $password = Sendlove_Utilities::createPassword(); $token = uniqid(); $login = Zend_Json::decode($this->_helper->api(array('app' => $this->_helper->api->name('login'), 'key' => $this->_helper->api->key('login'), 'token' => $token, 'admin_id' => $this->getSession()->userid, 'user_data' => array(array('username' => $this->getRequest()->getParam('email'), 'password' => $password, 'nickname' => $splitEmail[0], 'Active' => 1, 'Confirmed' => 1, 'status' => 'new'))), $this->_helper->api->endpoint('login') . 'admincreateusers')); if ($login['error'] == 0) { if ($login['token'] == $token) { if ($this->getRequest()->getParam('sendlove')) { $love = new Sendlove_Love(); $love->sendLove($this->getLoveEmail(), $this->getSession()->username, 'Welcome to SendLove'); } $companyMapper = new Admin_Model_CompanyMapper(); $company = $companyMapper->find($this->_helper->config('application')->companyid); if (!$this->sendCreateMail(array('creator_nickname' => $this->getSession()->nickname, 'creator_email' => $this->getSession()->username, 'company_name' => $company->getCompany_name(), 'url' => $this->_helper->config('application')->loveLoginUrl, 'user_username' => $this->getRequest()->getParam('email'), 'user_password' => $password))) { throw new Exception('Email could not be sent!'); } // Get the user data $user = $login['0'][0]; $newUsers[] = array('id' => $user['id'], 'username' => $user['username'], 'nickname' => $user['nickname'], 'active' => 1, 'confirmed' => 1); echo Zend_Json::encode(array('success' => true, 'message' => 'User successfully added', 'users' => $newUsers)); } else { echo Zend_Json::encode(array('success' => false, 'message' => $login['message'])); } } else { echo Zend_Json::encode(array('success' => false, 'message' => 'Could not add the user.')); } } else { echo Zend_Json::encode(array('success' => false, 'message' => 'No valid email address.')); } }
public function exportrewarderAction() { $this->_helper->viewRenderer->setNoRender(true); $request = $this->getReportRequest(); if (empty($request) && empty($request['start_date']) && empty($request['end_date'])) { echo Zend_Json::encode(array('success' => false, 'message' => 'Unable to export. Please check the period.')); return; } $rewarder = $this->getUserByReward($request); if (!empty($rewarder['rewarderlist'])) { $data = array(); foreach ($rewarder['rewarderlist'] as $row) { $data[] = array($row['username'], $row['nickname'], $row['points']); } $from = strtotime($request['start_date']); $to = strtotime($request['end_date']); $filename = 'rewarder-' . date('d.M.Y', $from) . "-" . date('d.M.Y', $to); $cvs_header = "Username,Nickname,Points\n"; $utilities = new Sendlove_Utilities(); $utilities->exportCSV($filename, $data, $cvs_header); exit; } }