Example #1
0
function save_item_action($data)
{
    global $fpdo;
    debug($data, 'posted data');
    $oVideo = new Video($data['path']);
    $video_id = $oVideo->get_videoID();
    $data['path'] = $video_id;
    debug($data['path'], 'posted path');
    $oItem = new Item($fpdo);
    $id = $oItem->add($data);
    debug($id, 'id');
}
Example #2
0
 public function getContent()
 {
     $output = '';
     $errors = array();
     $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT');
     $languages = Language::getLanguages(false);
     if (Tools::getValue('confirm_msg')) {
         $this->context->smarty->assign('confirmation', Tools::getValue('confirm_msg'));
     }
     if (Tools::isSubmit('submitnewItem')) {
         $id_item = (int) Tools::getValue('item_id');
         if ($id_item && Validate::isUnsignedId($id_item)) {
             $new_item = new Item($id_item);
         } else {
             $new_item = new Item();
         }
         $new_item->id_block = Tools::getValue('block_id');
         $new_item->type = Tools::getValue('linktype');
         $new_item->active = (int) Tools::getValue('active');
         $itemtitle_set = false;
         foreach ($languages as $language) {
             $item_title = Tools::getValue('item_title_' . $language['id_lang']);
             if (strlen($item_title) > 0) {
                 $itemtitle_set = true;
             }
             $new_item->title[$language['id_lang']] = $item_title;
         }
         if (!$itemtitle_set) {
             $lang_title = Language::getLanguage($this->context->language->id);
             if ($new_item->type == 'img') {
                 $errors[] = 'This Alt text field is required at least in ' . $lang_title['name'];
             } else {
                 $errors[] = 'This item title field is required at least in ' . $lang_title['name'];
             }
         }
         $new_item->class = Tools::getValue('custom_class');
         if ($new_item->type == 'link') {
             $new_item->icon = Tools::getValue('item_icon');
             $new_item->link = Tools::getValue('link_value');
         } elseif ($new_item->type == 'img') {
             if (isset($_FILES['item_img']) && strlen($_FILES['item_img']['name']) > 0) {
                 if (!($img_file = $this->moveUploadedImage($_FILES['item_img']))) {
                     $errors[] = 'An error occurred during the image upload.';
                 } else {
                     $new_item->icon = $img_file;
                     if (Tools::getValue('old_img') != '') {
                         $filename = Tools::getValue('old_img');
                         if (file_exists(dirname(__FILE__) . '/img/' . $filename)) {
                             @unlink(dirname(__FILE__) . '/img/' . $filename);
                         }
                     }
                 }
             } else {
                 $new_item->icon = Tools::getValue('old_img');
             }
             $new_item->link = Tools::getValue('link_value');
         } elseif ($new_item->type == 'html') {
             foreach ($languages as $language) {
                 $new_item->text[$language['id_lang']] = Tools::getValue('item_html_' . $language['id_lang']);
             }
         }
         if (!count($errors)) {
             if ($id_item && Validate::isUnsignedId($id_item)) {
                 if (!$new_item->update()) {
                     $errors[] = 'An error occurred while update data.';
                 }
             } else {
                 if (!$new_item->add()) {
                     $errors[] = 'An error occurred while saving data.';
                 }
             }
             if (!count($errors)) {
                 if ($id_item && Validate::isUnsignedId($id_item)) {
                     $this->context->smarty->assign('confirmation', $this->l('Item successfully updated.'));
                 } else {
                     $confirm_msg = $this->l('New item successfully added.');
                     Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                     Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg);
                 }
             }
         }
     } elseif (Tools::isSubmit('submit_del_item')) {
         $item_id = Tools::getValue('item_id');
         if ($item_id && Validate::isUnsignedId($item_id)) {
             $subs = $this->getSupMenu($item_id);
             $del = true;
             if ($subs && count($subs) > 0) {
             }
             foreach ($subs as $sub) {
                 $del &= $this->deleteSub($sub['id_sub']);
             }
             $item = new Item($item_id);
             if (!$item->delete() || !$del) {
                 $errors[] = 'An error occurred while delete item.';
             } else {
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 $this->context->smarty->assign('confirmation', $this->l('Delete successful.'));
             }
         }
     } elseif (Tools::isSubmit('submitnewsub')) {
         $id_sub = Tools::getValue('id_sub');
         if ($id_sub && Validate::isUnsignedId($id_sub)) {
             $sub = new Submenu($id_sub);
         } else {
             $sub = new Submenu();
         }
         $sub->id_parent = Tools::getValue('id_parent');
         $sub->width = Tools::getValue('subwidth');
         $sub->class = Tools::getValue('sub_class');
         $sub->active = Tools::getValue('active');
         if ($id_sub && Validate::isUnsignedId($id_sub)) {
             if (!$sub->update()) {
                 $errors[] = 'An error occurred while update data.';
             }
         } else {
             if (!$sub->checkAvaiable()) {
                 if (!$sub->add()) {
                     $errors[] = 'An error occurred while saving data.';
                 }
             } else {
                 $parent_item = new Item($sub->id_parent);
                 $errors[] = $parent_item->title[$this->context->language->id] . ' already have a sub.';
             }
         }
         if (!count($errors)) {
             if ($id_sub && Validate::isUnsignedId($id_sub)) {
                 $this->context->smarty->assign('confirmation', $this->l('Submenu successfully updated.'));
             } else {
                 $confirm_msg = $this->l('New sub successfully added.');
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg);
             }
         }
     } elseif (Tools::isSubmit('submit_del_sub')) {
         $id_sub = (int) Tools::getValue('id_sub');
         if ($id_sub && Validate::isUnsignedId($id_sub)) {
             if (!$this->deleteSub($id_sub)) {
                 $errors[] = 'An error occurred while delete sub menu.';
             } else {
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 $this->context->smarty->assign('confirmation', $this->l('Delete successful.'));
             }
         }
     } elseif (Tools::isSubmit('submitnewblock')) {
         $id_block = Tools::getValue('id_block');
         if ($id_block && Validate::isUnsignedId($id_block)) {
             $block = new Block($id_block);
         } else {
             $block = new Block();
         }
         $block->id_sub = Tools::getValue('id_sub');
         $block->width = Tools::getValue('block_widh');
         $block->class = Tools::getValue('block_class');
         if ($id_block && Validate::isUnsignedId($id_block)) {
             if (!$block->update()) {
                 $errors[] = 'An error occurred while update block.';
             }
         } else {
             if (!$block->add()) {
                 $errors[] = 'An error occurred while saving data.';
             }
         }
         if (!count($errors)) {
             if ($id_block && Validate::isUnsignedId($id_block)) {
                 $this->context->smarty->assign('confirmation', $this->l('Block successfully updated.'));
             } else {
                 $confirm_msg = $this->l('New block successfully added.');
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg);
             }
         }
     } elseif (Tools::isSubmit('submit_del_block')) {
         $id_block = Tools::getValue('id_block');
         if ($id_block && Validate::isUnsignedId($id_block)) {
             if (!$this->deleteBlock($id_block)) {
                 $errors[] = 'An error occurred while delete block.';
             } else {
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 $this->context->smarty->assign('confirmation', $this->l('Delete successful.'));
             }
         }
     } elseif (Tools::isSubmit('changeactive')) {
         $id_item = (int) Tools::getValue('item_id');
         if ($id_item && Validate::isUnsignedId($id_item)) {
             $item = new Item($id_item);
             $item->active = !$item->active;
             if (!$item->update()) {
                 $errors[] = $this->displayError('Could not change');
             } else {
                 $confirm_msg = $this->l('Successfully updated.');
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg);
             }
         }
     } elseif (Tools::isSubmit('changestatus')) {
         $id_sub = (int) Tools::getValue('id_sub');
         if ($id_sub && Validate::isUnsignedId($id_sub)) {
             $sub_menu = new Submenu($id_sub);
             $sub_menu->active = !$sub_menu->active;
             if (!$sub_menu->update()) {
                 $errors[] = $this->displayError('Could not change');
             } else {
                 $confirm_msg = $this->l('Submenu successfully updated.');
                 Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('topmenu.tpl'));
                 Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&confirm_msg=' . $confirm_msg);
             }
         }
     }
     $this->context->smarty->assign(array('admin_tpl_path' => $this->admin_tpl_path, 'postAction' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')));
     if (count($errors) > 0) {
         if (isset($errors) && count($errors)) {
             $output .= $this->displayError(implode('<br />', $errors));
         }
     }
     if (Tools::isSubmit('submit_edit_item') || Tools::isSubmit('submitnewItem') && count($errors) > 0) {
         $output .= $this->displayItemForm();
     } elseif (Tools::isSubmit('submit_edit_sub')) {
         $output .= $this->displaySubForm();
     } elseif (Tools::isSubmit('submit_new_block')) {
         $output .= $this->displayBlockForm();
     } else {
         $output .= $this->displayForm();
     }
     return $output;
 }
Example #3
0
		{
			//set permissions (since a umask could mess up the mkdir)
			chmod($sysDest, 01755);
		}
	}
	
	//create full save location
	$svDBFn = $dest . $svFn;
	
	//move the image
	if( !move_uploaded_file( $_FILES['image']['tmp_name'], "../images/" . $svDBFn ) )
	{
		kick(1, $data, 15);
	}
	
	$newItem = Item::add($data['name'], intval($data['cat'][0]), $data['desc'], $svDBFn, floatval($data['price']), intval($data['prep']), intval($data['lvl']));
	if( $newItem instanceof Item )
	{
		foreach( $data['ing'] as $ing )
		{
			$newItem->attach('ingredient', intval($ing));
		}
		
		foreach( $data['char'] as $char )
		{
			$newItem->attach('characteristic', intval($char));
		}
		
		$data['id'] = $newItem->itemid;
		
		kick(2, $data, 13);
Example #4
0
if ($_POST) {
    //dump($_FILES);
    $item->name = $_POST['name'];
    $item->article = $_POST['article'];
    $item->vendor_id = $_POST['vendor_id'];
    $item->category_id = $_POST['category_id'];
    $item->images = json_encode($_FILES['images']['name']);
    $item->status = isset($_POST['status']) ? 1 : 0;
    $num = 0;
    foreach ($_FILES['images']['name'] as $file) {
        upload('images', $num, 'items');
        $num++;
    }
    //exit;
    $state = false;
    if ($item->add()) {
        $state = true;
        unset($_POST);
    }
}
include 'templates/header.php';
include 'templates/sidemenu.php';
?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Add vendor Item
            <small>Add New vendor Items to the system</small>
<?php

include "../Errors.php";
require_once '../Classes/Item.php';
require_once '../Classes/Partida_Item.php';
$newId_Partida = isset($_POST["TempId_Partida"]) ? $_POST["TempId_Partida"] : "";
$newNom = $_POST['TempNom'];
$newDescripcio = $_POST['TempDescripcio'];
$newItem = new Item($newNom, $newDescripcio);
if (isset($_POST["TempId_Partida"]) && $newItem->get_id() == null) {
    $newItem->add();
    $newId_Item = $newItem->get_id();
    $Partida_Item = new Partida_Item($newId_Partida, $newId_Item['id_item']);
    //var_dump($Partida_Item);
    $Partida_Item->add();
    echo 'Item creat Correctament!!';
    header('Location: ../../panel.php');
} else {
    echo 'Error';
}
Example #6
0
 public function addItem()
 {
     $result = array('success' => false, 'status' => '', 'message' => '', 'records' => array());
     $item = new Item($this->db);
     $fields = $this->f3->get('POST.record');
     $this->f3->clear('POST');
     foreach ($fields as $field => $value) {
         if ($field == 'category') {
             $this->f3->set('POST.categoryId', $value[id]);
         } else {
             if ($field == 'cafe') {
                 $this->f3->set('POST.cafeId', $value[id]);
             } else {
                 $postParam = "POST.{$field}";
                 $this->f3->set($postParam, $value);
             }
         }
     }
     $item->add();
     $result[success] = true;
     $result[status] = 'success';
     $result[message] = 'Added Item successfully';
     header('Content-Type: application/json');
     echo json_encode($result, JSON_NUMERIC_CHECK);
     exit;
 }
 public function create()
 {
     $this->f3->set('page_head', 'Create Bookmark');
     //template
     $this->f3->set('view', 'item/create.htm');
     //menu
     $this->f3->set('topmenu', 'i');
     if ($this->f3->exists('POST.title')) {
         if ($this->f3->get('POST.title') != '') {
             //strip all tags and unsafe characters
             $t = $this->f3->get('POST.title');
             $this->f3->set('POST.title', $this->f3->scrub($t));
             $t = $this->f3->get('POST.url');
             $this->f3->set('POST.url', $this->f3->scrub($t));
             $t = $this->f3->get('POST.note');
             $this->f3->set('POST.note', $this->f3->scrub($t));
             $t = $this->f3->get('POST.cid');
             $this->f3->set('POST.cid', $this->f3->scrub($t));
             $t = $this->f3->get('POST.tags');
             $this->f3->set('POST.tags', $this->f3->scrub($t));
             //server side validation
             //if too long title
             if (strlen($this->f3->get('POST.title')) > 256) {
                 $this->f3->set('COOKIE.message', 'the title cannot be longer than 256 chars!');
                 $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s');
                 $this->f3->reroute('/i/create');
             }
             //if too long url
             if (strlen($this->f3->get('POST.url')) > 256) {
                 $this->f3->set('COOKIE.message', 'the url cannot be longer than 256 chars!');
                 $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s');
                 $this->f3->reroute('/i/create');
             }
             //if too long note
             if (strlen($this->f3->get('POST.note')) > 20000) {
                 $this->f3->set('COOKIE.message', 'the note cannot be longer than 20000 chars!');
                 $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s');
                 $this->f3->reroute('/i/create');
             }
             //if cat is not numeric
             if (!is_numeric($this->f3->get('POST.cid'))) {
                 //$this->f3->set('COOKIE.message','the category ID must be numeric!');
                 //$this->f3->set('COOKIE.messagetype','alert-danger hide10s');
                 //$this->f3->reroute('/i/create');
                 $this->f3->set('POST.cid', 0);
             }
             //if too long tags
             if (strlen($this->f3->get('POST.tags')) > 5000) {
                 $this->f3->set('COOKIE.message', 'tags cannot be longer than 5000 chars!');
                 $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s');
                 $this->f3->reroute('/i/create');
             }
             //get unique tok
             $utok = new Item($this->db);
             $randtok = rand(100000000, 999999999);
             while ($utok->itemcountByTok($randtok) > 0) {
                 $randtok = rand(100000000, 999999999);
             }
             //variables
             $item = new Item($this->db);
             $item->tok = $randtok;
             $item->add();
             //last inserted id
             $iid = $item->_id;
             //add tags
             if ($this->f3->exists('POST.tags')) {
                 $tid = 0;
                 $tags = explode(',', $this->f3->get('POST.tags'));
                 foreach ($tags as $t) {
                     $t = trim($t);
                     if ($t != '') {
                         $this->f3->clear('TAGS');
                         $ifexists = new Tag($this->db);
                         $ifexists->getByName(strtolower($t));
                         //get id
                         if ($this->f3->exists('TAGS.id')) {
                             $tid = $this->f3->get('TAGS.id');
                         } else {
                             //insert new tag
                             $newtag = new Tag($this->db);
                             $newtag->title = strtolower(preg_replace('|[^0-9A-Za-z \\-\\/+]|', '', $t));
                             $newtag->label = preg_replace('|[^0-9A-Za-z \\-\\/+]|', '', $t);
                             $newtag->url = toUrl($t);
                             //get unique tok
                             $utok = new Tag($this->db);
                             $randtok = rand(100000000, 999999999);
                             while ($utok->tagcountByTok($randtok) > 0) {
                                 $randtok = rand(100000000, 999999999);
                             }
                             $newtag->tok = $randtok;
                             $newtag->add();
                             //get last inserted id
                             $tid = $newtag->_id;
                         }
                         //add to Tag2Item
                         $t2i = new Tag2Item($this->db);
                         //insert lastinsertedid
                         $t2i->tid = $tid;
                         $t2i->iid = $iid;
                         $t2i->add();
                     }
                 }
             }
         }
         if ($this->f3->get('POST.title') != '') {
             $this->f3->set('COOKIE.message', 'Bookmark was created');
             $this->f3->set('COOKIE.messagetype', 'alert-success hide5s');
             $this->f3->reroute('/');
         } else {
             //if not valid
             $this->f3->set('message', 'The field title is required!');
             $this->f3->set('messagetype', 'alert-error hide5s');
         }
     }
     //breadcrumbs
     $this->f3->set('breadcrumb', array(array("url" => NULL, "name" => "Create bookmark")));
 }
Example #8
0
 function add()
 {
     if (isset($_POST['content']) && $_POST['content'] != '' || $this->config->items->titles->enabled == TRUE && isset($_POST['title']) && $_POST['title'] != '' || $this->config->items->uploads->enabled == TRUE && isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') {
         $error = '';
         // Form validation
         if ($this->config->items->titles->enabled == FALSE && $_POST['content'] == '') {
             $error .= ucfirst($this->config->items->name) . ' must include ' . strtolower($this->config->items->content->name) . '.<br />';
         }
         if ($this->config->items->uploads->enabled == TRUE && $_FILES['file']['name'] != '') {
             if ($_FILES['file']['error'] > 0) {
                 $error .= 'Error code: ' . $_FILES['file']['error'] . '<br />';
             }
             if (!in_array($_FILES['file']['type'], $this->config->items->uploads->mime_types)) {
                 $error .= 'Invalid file type: ' . $_FILES['file']['type'] . '<br />';
             }
             if ($_FILES['file']['size'] > $this->config->items->uploads->max_size) {
                 $error .= 'File too large.<br />';
             }
         }
         // Error processing
         if ($error == '') {
             // No error so proceed...
             if ($this->config->items->uploads->enabled == TRUE && $_FILES['file']['name'] != '') {
                 include 'lib/upload.php';
                 $filename = upload($_FILES['file'], $this->config->items->uploads->directory);
                 // try {
                 //
                 //   $upload = $this->s3->upload(
                 //     $this->config->items->uploads->aws_s3_bucket,
                 //     $_FILES['file']['name'],
                 //     fopen($_FILES['file']['tmp_name'], 'rb'),
                 //     'public-read'
                 //   );
                 //
                 //   $url = $upload->get('ObjectURL');
                 //
                 // } catch (Exception $e) {}
                 $item_id = Item::add($_SESSION['user_id'], $_POST['content'], $_POST['title'], $filename);
             } else {
                 $item_id = Item::add($_SESSION['user_id'], $_POST['content'], $_POST['title']);
             }
             // Give points
             if (isset($this->plugins->points)) {
                 $this->plugins->points->update($_SESSION['user_id'], $this->plugins->points['per_item']);
             }
             // Log item add
             if (isset($this->plugins->log)) {
                 $this->plugins->log->add($_SESSION['user_id'], 'item', $item_id, 'add', "title = {$_POST['title']}\ncontent = {$_POST['content']}");
             }
             Application::flash('success', ucfirst($this->config->items->name) . ' added!');
             // Go forth!
             header('Location: ' . $this->url_for('users', 'show', $_SESSION['user_id']));
             exit;
         } else {
             // There was an error
             // Propagate get vars to be picked up by the form
             $this->uri['params']['title'] = $_POST['title'];
             $this->uri['params']['content'] = $_POST['content'];
             // Show error message
             Application::flash('error', $error);
             $this->loadView('items/add');
             exit;
         }
     } else {
         $this->loadView('items/add');
     }
 }