本文整理匯總了PHP中Attachment::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP Attachment::add方法的具體用法?PHP Attachment::add怎麽用?PHP Attachment::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Attachment
的用法示例。
在下文中一共展示了Attachment::add方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processAddAttachments
/**
* Method processAddAttachments() : Change name of file which are uploaded for this product
* Rules:
* - For the first upload the filename has been : name-of-product.extention
* - For the second upload : name-of-product-1.extention
* - ...
*
* @module now_seo_links
* @return void
*
* @see AdminProductsControllerCore::processAddAttachments()
*/
public function processAddAttachments()
{
$languages = Language::getLanguages(false);
$is_attachment_name_valid = false;
foreach ($languages as $language) {
$attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
if (Tools::strlen($attachment_name_lang) > 0) {
$is_attachment_name_valid = true;
}
if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) {
$this->errors[] = Tools::displayError('Invalid Name');
} elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) {
$this->errors[] = sprintf(Tools::displayError('The name is too long (%d chars max).'), 32);
}
if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) {
$this->errors[] = Tools::displayError('Invalid description');
}
}
if (!$is_attachment_name_valid) {
$this->errors[] = Tools::displayError('An attachment name is required.');
}
if (empty($this->errors)) {
if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) {
if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
$this->errors[] = sprintf($this->l('The file is too large. Maximum size allowed is: %1$d kB. The file you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', ''));
} else {
do {
$uniqid = sha1(microtime());
} while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
$this->errors[] = $this->l('File copy failed');
}
@unlink($_FILES['attachment_file']['tmp_name']);
}
} elseif ((int) $_FILES['attachment_file']['error'] === 1) {
$max_upload = (int) ini_get('upload_max_filesize');
$max_post = (int) ini_get('post_max_size');
$upload_mb = min($max_upload, $max_post);
$this->errors[] = sprintf($this->l('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>');
} else {
$this->errors[] = Tools::displayError('The file is missing.');
}
if (empty($this->errors) && isset($uniqid)) {
$attachment = new Attachment();
foreach ($languages as $language) {
if (Tools::getIsset('attachment_name_' . (int) $language['id_lang'])) {
$attachment->name[(int) $language['id_lang']] = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
}
if (Tools::getIsset('attachment_description_' . (int) $language['id_lang'])) {
$attachment->description[(int) $language['id_lang']] = Tools::getValue('attachment_description_' . (int) $language['id_lang']);
}
}
if (Tools::getIsset('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))) {
$sFilename = $_FILES['attachment_file']['name'];
$sExtention = substr($sFilename, strrpos($sFilename, '.') + 1);
$attachment->file_name = Tools::link_rewrite(trim(Tools::getValue('name_' . (int) Configuration::get('PS_LANG_DEFAULT'))));
// On regarde si c'est le premier document joint au produit ou pas
$aAttachmentOfProduct = $attachment->getAttachments(Context::getContext()->language->id, (int) Tools::getValue('id_product'));
$iNb = count($aAttachmentOfProduct);
if ($iNb > 0) {
$attachment->file_name .= '-' . $iNb;
}
$attachment->file_name .= '.' . $sExtention;
}
$attachment->file = $uniqid;
$attachment->mime = $_FILES['attachment_file']['type'];
if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) {
$this->errors[] = Tools::displayError('Invalid file extension');
}
if (!Validate::isGenericName($attachment->file_name)) {
$this->errors[] = Tools::displayError('Invalid file name');
}
if (Tools::strlen($attachment->file_name) > 128) {
$this->errors[] = Tools::displayError('The file name is too long.');
}
if (empty($this->errors)) {
$res = $attachment->add();
if (!$res) {
$this->errors[] = Tools::displayError('This attachment was unable to be loaded into the database.');
} else {
$id_product = (int) Tools::getValue($this->identifier);
$res = $attachment->attachProduct($id_product);
if (!$res) {
$this->errors[] = Tools::displayError('We were unable to associate this attachment to a product.');
}
}
} else {
$this->errors[] = Tools::displayError('Invalid file');
//.........這裏部分代碼省略.........
示例2: postProcess
/**
* postProcess handle every checks before saving products information
*
* @param mixed $token
* @return void
*/
public function postProcess($token = null)
{
global $cookie, $currentIndex;
// Add a new product
if (Tools::isSubmit('submitAddproduct') || Tools::isSubmit('submitAddproductAndStay') || Tools::isSubmit('submitAddProductAndPreview')) {
if (Tools::getValue('id_product') && $this->tabAccess['edit'] === '1' || $this->tabAccess['add'] === '1' && !Tools::isSubmit('id_product')) {
$this->submitAddproduct($token);
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
}
/* Delete a product in the download folder */
if (Tools::getValue('deleteVirtualProduct')) {
if ($this->tabAccess['delete'] === '1') {
$this->deleteVirtualProduct();
} else {
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
} elseif (Tools::isSubmit('submitAddAttachments')) {
if ($this->tabAccess['add'] === '1') {
$languages = Language::getLanguages(false);
$is_attachment_name_valid = false;
foreach ($languages as $language) {
$attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
if (strlen($attachment_name_lang) > 0) {
$is_attachment_name_valid = true;
}
if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) {
$this->_errors[] = Tools::displayError('Invalid Name');
} elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) {
$this->_errors[] = Tools::displayError('Name is too long');
}
if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) {
$this->_errors[] = Tools::displayError('Invalid description');
}
}
if (!$is_attachment_name_valid) {
$this->_errors[] = Tools::displayError('Attachment Name Required');
}
if (empty($this->_errors)) {
if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) {
if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
$this->_errors[] = $this->l('File too large, maximum size allowed:') . ' ' . Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 . ' ' . $this->l('kb') . '. ' . $this->l('File size you\'re trying to upload is:') . number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '') . $this->l('kb');
} else {
do {
$uniqid = sha1(microtime());
} while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
$this->_errors[] = $this->l('File copy failed');
}
@unlink($_FILES['attachment_file']['tmp_name']);
}
} elseif ((int) $_FILES['attachment_file']['error'] === 1) {
$max_upload = (int) ini_get('upload_max_filesize');
$max_post = (int) ini_get('post_max_size');
$upload_mb = min($max_upload, $max_post);
$this->_errors[] = $this->l('the File') . ' <b>' . $_FILES['attachment_file']['name'] . '</b> ' . $this->l('exceeds the size allowed by the server, this limit is set to') . ' <b>' . $upload_mb . $this->l('Mb') . '</b>';
}
if (empty($this->_errors) && isset($uniqid)) {
$attachment = new Attachment();
foreach ($languages as $language) {
if (isset($_POST['attachment_name_' . (int) $language['id_lang']])) {
$attachment->name[(int) $language['id_lang']] = pSQL($_POST['attachment_name_' . (int) $language['id_lang']]);
}
if (isset($_POST['attachment_description_' . (int) $language['id_lang']])) {
$attachment->description[(int) $language['id_lang']] = pSQL($_POST['attachment_description_' . (int) $language['id_lang']]);
}
}
$attachment->file = $uniqid;
$attachment->mime = $_FILES['attachment_file']['type'];
$attachment->file_name = pSQL($_FILES['attachment_file']['name']);
if (empty($attachment->mime) or Tools::strlen($attachment->mime) > 128) {
$this->_errors[] = Tools::displayError('Invalid file extension');
}
if (!Validate::isGenericName($attachment->file_name)) {
$this->_errors[] = Tools::displayError('Invalid file name');
}
if (Tools::strlen($attachment->file_name) > 128) {
$this->_errors[] = Tools::displayError('File name too long');
}
if (!sizeof($this->_errors)) {
$attachment->add();
Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue($this->identifier) . '&id_category=' . (int) Tools::getValue('id_category') . '&addproduct&conf=4&tabs=6&token=' . ($token ? $token : $this->token));
} else {
$this->_errors[] = Tools::displayError('Invalid file');
}
}
}
} else {
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
} elseif (Tools::isSubmit('submitAttachments')) {
if ($this->tabAccess['edit'] === '1') {
if ($id = (int) Tools::getValue($this->identifier)) {
//.........這裏部分代碼省略.........
示例3: crop_upload
/**
* 圖片裁切
*
* @return boolean
*/
public function crop_upload()
{
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
$pic = $GLOBALS["HTTP_RAW_POST_DATA"];
if (isset($_GET['width']) && !empty($_GET['width'])) {
$width = intval($_GET['width']);
}
if (isset($_GET['height']) && !empty($_GET['height'])) {
$height = intval($_GET['height']);
}
if (isset($_GET['file']) && !empty($_GET['file'])) {
if (is_image($_GET['file']) == false) {
exit;
}
if (strpos($_GET['file'], C('attachment', 'upload_url')) !== false) {
$file = $_GET['file'];
$basename = basename($file);
$filepath = str_replace(SITE_URL, '', dirname($file)) . '/';
if (strpos($basename, 'thumb_') !== false) {
$file_arr = explode('_', $basename);
$basename = array_pop($file_arr);
}
$new_file = 'thumb_' . $width . '_' . $height . '_' . $basename;
} else {
$application = trim($_GET['application']);
$catid = intval($_GET['catid']);
$attachment = new Attachment($application, $catid);
$uploadedfile['filename'] = basename($_GET['file']);
$uploadedfile['fileext'] = File::get_suffix($_GET['file']);
if (in_array($uploadedfile['fileext'], array('jpg', 'gif', 'jpeg', 'png', 'bmp'))) {
$uploadedfile['isimage'] = 1;
}
$file_path = C('attachment', 'upload_path') . date('Y/md/');
Folder::mk($file_path);
$new_file = date('Ymdhis') . rand(100, 999) . '.' . $uploadedfile['fileext'];
$uploadedfile['filepath'] = date('Y/md/') . $new_file;
$aid = $attachment->add($uploadedfile);
$filepath = str_replace(SITE_URL, '', C('attachment', 'upload_url')) . date('Y/md/');
}
file_put_contents(BASE_PATH . $filepath . $new_file, $pic);
} else {
return false;
}
echo SITE_URL . $filepath . $new_file;
exit;
}
}
示例4: importer
function importer($path, $node, $line)
{
global $blogid, $migrational, $items, $item;
switch ($path) {
case '/blog/setting':
setProgress($item++ / $items * 100, _t('블로그 설정을 복원하고 있습니다.'));
$setting = new BlogSetting();
if (isset($node['title'][0]['.value'])) {
$setting->title = $node['title'][0]['.value'];
}
if (isset($node['description'][0]['.value'])) {
$setting->description = $node['description'][0]['.value'];
}
if (isset($node['banner'][0]['name'][0]['.value'])) {
$setting->banner = $node['banner'][0]['name'][0]['.value'];
}
if (isset($node['useSloganOnPost'][0]['.value'])) {
$setting->useSloganOnPost = $node['useSloganOnPost'][0]['.value'];
}
if (isset($node['postsOnPage'][0]['.value'])) {
$setting->postsOnPage = $node['postsOnPage'][0]['.value'];
}
if (isset($node['postsOnList'][0]['.value'])) {
$setting->postsOnList = $node['postsOnList'][0]['.value'];
}
if (isset($node['postsOnFeed'][0]['.value'])) {
$setting->postsOnFeed = $node['postsOnFeed'][0]['.value'];
}
if (isset($node['publishWholeOnFeed'][0]['.value'])) {
$setting->publishWholeOnFeed = $node['publishWholeOnFeed'][0]['.value'];
}
if (isset($node['acceptGuestComment'][0]['.value'])) {
$setting->acceptGuestComment = $node['acceptGuestComment'][0]['.value'];
}
if (isset($node['acceptcommentOnGuestComment'][0]['.value'])) {
$setting->acceptcommentOnGuestComment = $node['acceptcommentOnGuestComment'][0]['.value'];
}
if (isset($node['language'][0]['.value'])) {
$setting->language = $node['language'][0]['.value'];
}
if (isset($node['timezone'][0]['.value'])) {
$setting->timezone = $node['timezone'][0]['.value'];
}
if (!$setting->save()) {
user_error(__LINE__ . $setting->error);
}
if (!empty($setting->banner) && !empty($node['banner'][0]['content'][0]['.stream'])) {
Attachment::confirmFolder();
Utils_Base64Stream::decode($node['banner'][0]['content'][0]['.stream'], Path::combine(ROOT, 'attach', $blogid, $setting->banner));
Attachment::adjustPermission(Path::combine(ROOT, 'attach', $blogid, $setting->banner));
fclose($node['banner'][0]['content'][0]['.stream']);
unset($node['banner'][0]['content'][0]['.stream']);
}
return true;
case '/blog/category':
setProgress($item++ / $items * 100, _t('분류를 복원하고 있습니다.'));
$category = new Category();
$category->name = $node['name'][0]['.value'];
$category->priority = $node['priority'][0]['.value'];
if (isset($node['root'][0]['.value'])) {
$category->id = 0;
}
if (!$category->add()) {
user_error(__LINE__ . $category->error);
}
if (isset($node['category'])) {
for ($i = 0; $i < count($node['category']); $i++) {
$childCategory = new Category();
$childCategory->parent = $category->id;
$cursor =& $node['category'][$i];
$childCategory->name = $cursor['name'][0]['.value'];
$childCategory->priority = $cursor['priority'][0]['.value'];
if (!$childCategory->add()) {
user_error(__LINE__ . $childCategory->error);
}
}
}
return true;
case '/blog/post':
setProgress($item++ / $items * 100, _t('글을 복원하고 있습니다.'));
$post = new Post();
$post->id = $node['id'][0]['.value'];
$post->slogan = @$node['.attributes']['slogan'];
$post->visibility = $node['visibility'][0]['.value'];
if (isset($node['starred'][0]['.value'])) {
$post->starred = $node['starred'][0]['.value'];
} else {
$post->starred = 0;
}
$post->title = $node['title'][0]['.value'];
$post->content = $node['content'][0]['.value'];
$post->contentformatter = isset($node['content'][0]['.attributes']['formatter']) ? $node['content'][0]['.attributes']['formatter'] : 'ttml';
$post->contenteditor = isset($node['content'][0]['.attributes']['editor']) ? $node['content'][0]['.attributes']['editor'] : 'modern';
$post->location = $node['location'][0]['.value'];
$post->password = isset($node['password'][0]['.value']) ? $node['password'][0]['.value'] : null;
$post->acceptcomment = $node['acceptComment'][0]['.value'];
$post->accepttrackback = $node['acceptTrackback'][0]['.value'];
$post->published = $node['published'][0]['.value'];
if (isset($node['longitude'][0]['.value'])) {
$post->longitude = $node['longitude'][0]['.value'];
//.........這裏部分代碼省略.........
示例5: processAddAttachments
/**
* Upload new attachment
*
* @return void
*/
public function processAddAttachments()
{
$languages = Language::getLanguages(false);
$is_attachment_name_valid = false;
foreach ($languages as $language) {
$attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
if (Tools::strlen($attachment_name_lang) > 0) {
$is_attachment_name_valid = true;
}
if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) {
$this->errors[] = Tools::displayError('Invalid Name');
} elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) {
$this->errors[] = sprintf(Tools::displayError('Name is too long (%d chars max).'), 32);
}
if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) {
$this->errors[] = Tools::displayError('Invalid description');
}
}
if (!$is_attachment_name_valid) {
$this->errors[] = Tools::displayError('Attachment name required');
}
if (empty($this->errors)) {
if (isset($_FILES['attachment_file']) && is_uploaded_file($_FILES['attachment_file']['tmp_name'])) {
if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
$this->errors[] = sprintf($this->l('File too large, maximum size allowed: %1$d kB. File size you\'re trying to upload is: %2$d kB.'), Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', ''));
} else {
do {
$uniqid = sha1(microtime());
} while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
$this->errors[] = $this->l('File copy failed');
}
@unlink($_FILES['attachment_file']['tmp_name']);
}
} elseif ((int) $_FILES['attachment_file']['error'] === 1) {
$max_upload = (int) ini_get('upload_max_filesize');
$max_post = (int) ini_get('post_max_size');
$upload_mb = min($max_upload, $max_post);
$this->errors[] = sprintf($this->l('The File %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.'), '<b>' . $_FILES['attachment_file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>');
} else {
$this->errors[] = Tools::displayError('File is missing');
}
if (empty($this->errors) && isset($uniqid)) {
$attachment = new Attachment();
foreach ($languages as $language) {
if (Tools::getIsset('attachment_name_' . (int) $language['id_lang'])) {
$attachment->name[(int) $language['id_lang']] = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
}
if (Tools::getIsset('attachment_description_' . (int) $language['id_lang'])) {
$attachment->description[(int) $language['id_lang']] = Tools::getValue('attachment_description_' . (int) $language['id_lang']);
}
}
$attachment->file = $uniqid;
$attachment->mime = $_FILES['attachment_file']['type'];
$attachment->file_name = $_FILES['attachment_file']['name'];
if (empty($attachment->mime) || Tools::strlen($attachment->mime) > 128) {
$this->errors[] = Tools::displayError('Invalid file extension');
}
if (!Validate::isGenericName($attachment->file_name)) {
$this->errors[] = Tools::displayError('Invalid file name');
}
if (Tools::strlen($attachment->file_name) > 128) {
$this->errors[] = Tools::displayError('File name too long');
}
if (empty($this->errors)) {
$res = $attachment->add();
if (!$res) {
$this->errors[] = Tools::displayError('Unable to add this attachment in the database');
} else {
$id_product = (int) Tools::getValue($this->identifier);
$res = $attachment->attachProduct($id_product);
if (!$res) {
$this->errors[] = Tools::displayError('Unable to associate this attachment to product');
}
}
} else {
$this->errors[] = Tools::displayError('Invalid file');
}
}
}
}
示例6: extractAttachments
/**
* Method used to extract and associate attachments in an email
* to the given issue.
*
* @access public
* @param integer $issue_id The issue ID
* @param string $full_email The full contents of the email
* @param boolean $internal_only Whether these files are supposed to be internal only or not
* @param integer $associated_note_id The note ID that these attachments should be associated with
* @return void
*/
function extractAttachments($issue_id, $full_email, $internal_only = false, $associated_note_id = false)
{
// figure out who should be the 'owner' of this attachment
$structure = Mime_Helper::decode($full_email, false, false);
$sender_email = strtolower(Mail_API::getEmailAddress($structure->headers['from']));
$usr_id = User::getUserIDByEmail($sender_email);
$unknown_user = false;
if (empty($usr_id)) {
$prj_id = Issue::getProjectID($issue_id);
if (Customer::hasCustomerIntegration($prj_id)) {
// try checking if a customer technical contact has this email associated with it
list(, $contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
if (!empty($contact_id)) {
$usr_id = User::getUserIDByContactID($contact_id);
}
}
if (empty($usr_id)) {
// if we couldn't find a real customer by that email, set the usr_id to be the system user id,
// and store the actual email address in the unknown_user field.
$usr_id = APP_SYSTEM_USER_ID;
$unknown_user = $structure->headers['from'];
}
}
// now for the real thing
$attachments = Mime_Helper::getAttachments($full_email);
if (count($attachments) > 0) {
if (empty($associated_note_id)) {
$history_log = 'Attachment originated from an email';
} else {
$history_log = 'Attachment originated from a note';
}
$attachment_id = Attachment::add($issue_id, $usr_id, $history_log, $internal_only, $unknown_user, $associated_note_id);
for ($i = 0; $i < count($attachments); $i++) {
Attachment::addFile($attachment_id, $issue_id, $attachments[$i]['filename'], $attachments[$i]['filetype'], $attachments[$i]['blob']);
}
// mark the note as having attachments (poor man's caching system)
if ($associated_note_id != false) {
Note::setAttachmentFlag($associated_note_id);
}
}
}
示例7: update_ticket
public function update_ticket()
{
if (!isset($_POST['ticket_id'])) {
error(__("Error"), __("No ticket ID specified.", "progress"));
}
$ticket = new Ticket($_POST['ticket_id']);
if ($ticket->no_results) {
error(__("Error"), __("Invalid ticket ID specified.", "progress"));
}
if (!$ticket->editable()) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this ticket.", "progress"));
}
$files = array();
if (!empty($_FILES['attachment'])) {
foreach ($_FILES['attachment'] as $key => $val) {
foreach ($val as $file => $attr) {
$files[$file][$key] = $attr;
}
}
}
foreach ($files as $attachment) {
if ($attachment['error'] != 4) {
$path = upload($attachment, null, "attachments");
Attachment::add(basename($path), $path, "ticket", $ticket->id);
}
}
$ticket->update($_POST['title'], $_POST['description']);
Flash::notice(__("Ticket updated.", "progress"), $ticket->url());
}
示例8: update_version
public function update_version()
{
if (!isset($_POST['version_id'])) {
error(__("Error"), __("No version ID specified.", "extend"));
}
$version = new Version($_POST['version_id'], array("filter" => false));
if ($version->no_results) {
error(__("Error"), __("Invalid version ID specified.", "extend"));
}
if (!$version->editable()) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this version.", "extend"));
}
$files = array();
if (!empty($_FILES['attachment'])) {
foreach ($_FILES['attachment'] as $key => $val) {
foreach ($val as $file => $attr) {
$files[$file][$key] = $attr;
}
}
}
foreach ($files as $attachment) {
if ($attachment['error'] != 4) {
$path = upload($attachment, null, "attachments");
Attachment::add(basename($path), $path, "version", $version->id);
}
}
$version->extension->update($_POST['name']);
if ($_FILES['extension']['error'] == 0) {
@unlink(uploaded($version->filename, true));
# Add the MIT license if no license is specified
$zip = new ZipArchive();
if ($zip->open($_FILES['extension']['tmp_name']) === true and $zip->locateName("LICENSE") === false) {
$header = "Copyright (c) " . date("Y") . " " . oneof($visitor->full_name, $visitor->login);
$mit = <<<EOF
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name(s) of the above
copyright holders shall not be used in advertising or otherwise
to promote the sale, use or other dealings in this Software
without prior written authorization.
EOF;
$zip->addFromString("LICENSE", $header . "\n\n" . $mit . "\n");
$zip->close();
}
$filename = upload($_FILES['extension'], "zip", "extension/" . pluralize($version->extension->type->url));
} else {
$filename = $version->filename;
}
if ($_FILES['image']['error'] == 0) {
@unlink(uploaded($version->image, true));
$image = upload($_FILES['image'], null, "previews/" . pluralize($version->extension->type->url));
} else {
$image = $version->image;
}
$version->update($_POST['number'], $_POST['description'], comma_sep($_POST['compatible']), comma_sep($_POST['tags']), $filename, $image);
Flash::notice(__("Version updated.", "extend"), $version->url());
}
示例9: insert
/**
* Method used to add a new issue using the normal report form.
*
* @access public
* @return integer The new issue ID
*/
function insert()
{
global $HTTP_POST_VARS, $HTTP_POST_FILES, $insert_errors;
$usr_id = Auth::getUserID();
$prj_id = Auth::getCurrentProject();
$initial_status = Project::getInitialStatus($prj_id);
$insert_errors = array();
$missing_fields = array();
if ($HTTP_POST_VARS["category"] == '-1') {
$missing_fields[] = "Category";
}
if ($HTTP_POST_VARS["priority"] == '-1') {
$missing_fields[] = "Priority";
}
if ($HTTP_POST_VARS["estimated_dev_time"] == '') {
$HTTP_POST_VARS["estimated_dev_time"] = 0;
}
// add new issue
$stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n (\n iss_prj_id,\n";
if (!empty($HTTP_POST_VARS["group"])) {
$stmt .= "iss_grp_id,\n";
}
if (!empty($HTTP_POST_VARS["category"])) {
$stmt .= "iss_prc_id,\n";
}
if (!empty($HTTP_POST_VARS["release"])) {
$stmt .= "iss_pre_id,\n";
}
if (!empty($HTTP_POST_VARS["priority"])) {
$stmt .= "iss_pri_id,\n";
}
$stmt .= "iss_usr_id,";
if (!empty($initial_status)) {
$stmt .= "iss_sta_id,";
}
if (Customer::hasCustomerIntegration($prj_id)) {
$stmt .= "\n iss_customer_id,\n iss_customer_contact_id,\n iss_contact_person_lname,\n iss_contact_person_fname,\n iss_contact_email,\n iss_contact_phone,\n iss_contact_timezone,";
}
$stmt .= "\n iss_created_date,\n iss_last_public_action_date,\n iss_last_public_action_type,\n iss_summary,\n iss_description,\n iss_dev_time,\n iss_private,\n iss_root_message_id\n ) VALUES (\n " . $prj_id . ",\n";
if (!empty($HTTP_POST_VARS["group"])) {
$stmt .= Misc::escapeInteger($HTTP_POST_VARS["group"]) . ",\n";
}
if (!empty($HTTP_POST_VARS["category"])) {
$stmt .= Misc::escapeInteger($HTTP_POST_VARS["category"]) . ",\n";
}
if (!empty($HTTP_POST_VARS["release"])) {
$stmt .= Misc::escapeInteger($HTTP_POST_VARS["release"]) . ",\n";
}
if (!empty($HTTP_POST_VARS["priority"])) {
$stmt .= Misc::escapeInteger($HTTP_POST_VARS["priority"]) . ",";
}
// if we are creating an issue for a customer, put the
// main customer contact as the reporter for it
if (Customer::hasCustomerIntegration($prj_id)) {
$contact_usr_id = User::getUserIDByContactID($HTTP_POST_VARS['contact']);
if (empty($contact_usr_id)) {
$contact_usr_id = $usr_id;
}
$stmt .= Misc::escapeInteger($contact_usr_id) . ",";
} else {
$stmt .= $usr_id . ",";
}
if (!empty($initial_status)) {
$stmt .= Misc::escapeInteger($initial_status) . ",";
}
if (Customer::hasCustomerIntegration($prj_id)) {
$stmt .= "\n " . Misc::escapeInteger($HTTP_POST_VARS['customer']) . ",\n " . Misc::escapeInteger($HTTP_POST_VARS['contact']) . ",\n '" . Misc::escapeString($HTTP_POST_VARS["contact_person_lname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_person_fname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_email"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_phone"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["contact_timezone"]) . "',";
}
$stmt .= "\n '" . Date_API::getCurrentDateGMT() . "',\n '" . Date_API::getCurrentDateGMT() . "',\n 'created',\n '" . Misc::escapeString($HTTP_POST_VARS["summary"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["description"]) . "',\n " . Misc::escapeString($HTTP_POST_VARS["estimated_dev_time"]) . ",\n " . Misc::escapeInteger($HTTP_POST_VARS["private"]) . " ,\n '" . Misc::escapeString(Mail_API::generateMessageID()) . "'\n )";
$res = $GLOBALS["db_api"]->dbh->query($stmt);
if (PEAR::isError($res)) {
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
return -1;
} else {
$new_issue_id = $GLOBALS["db_api"]->get_last_insert_id();
$has_TAM = false;
$has_RR = false;
$info = User::getNameEmail($usr_id);
// log the creation of the issue
History::add($new_issue_id, Auth::getUserID(), History::getTypeID('issue_opened'), 'Issue opened by ' . User::getFullName(Auth::getUserID()));
$emails = array();
if (Customer::hasCustomerIntegration($prj_id)) {
if (@count($HTTP_POST_VARS['contact_extra_emails']) > 0) {
$emails = $HTTP_POST_VARS['contact_extra_emails'];
}
// add the primary contact to the notification list
if ($HTTP_POST_VARS['add_primary_contact'] == 'yes') {
$contact_email = User::getEmailByContactID($HTTP_POST_VARS['contact']);
if (!empty($contact_email)) {
$emails[] = $contact_email;
}
}
// if there are any technical account managers associated with this customer, add these users to the notification list
$managers = Customer::getAccountManagers($prj_id, $HTTP_POST_VARS['customer']);
//.........這裏部分代碼省略.........
示例10: importAttachments
protected function importAttachments()
{
$this->truncateTables(array('attachment', 'attachment_lang'));
$handle = $this->openCsvFile('attachments.csv');
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
$res = false;
$fields = $this->filterFields('Attachment', $this->attachments_fields, $line);
if (!isset($fields['id'])) {
$attacment = new Attachment((int) $line[0]);
$attacment->id = $line[0];
} else {
$attacment = new Attachment((int) $fields['id']);
}
foreach ($fields as $key => $field) {
if ($key == 'name' || $key == 'description') {
$attacment->{$key} = $this->multilFild($field);
} else {
$attacment->{$key} = $field;
}
}
$attacment->force_id = true;
if (!$res) {
$attacment->add();
}
}
$this->closeCsvFile($handle);
return true;
}