/**
  * When an existing item is switched from public to private, it should be
  * removed from Solr.
  */
 public function testRemoveItemWhenSetPrivate()
 {
     // Insert public item.
     $item = insert_item(array('public' => true));
     // Set the item private.
     update_item($item, array('public' => false));
     // Should remove the Solr document.
     $this->_assertNotRecordInSolr($item);
 }
Пример #2
0
 /**
  * `hookAfterSaveItem` should update records that reference the item.
  */
 public function testHookAfterSaveItem()
 {
     $item = $this->_item('title');
     $exhibit = $this->_exhibit();
     $record = $this->_record($exhibit, $item);
     // Update the item.
     update_item($item, array(), array('Dublin Core' => array('Title' => array(array('text' => 'title', 'html' => false)))));
     // Record should be compiled.
     $record = $this->_reload($record);
     $this->assertEquals('title', $record->item_title);
 }
function process_item($window, $id)
{
    global $mainwin;
    switch ($id) {
        case IDOK:
            if (update_item($window)) {
                wb_destroy_window($window);
                update_items($mainwin);
            }
            break;
        case IDCANCEL:
        case IDCLOSE:
            wb_destroy_window($window);
            break;
    }
}
Пример #4
0
function add_item(&$cart, $key, $quantity)
{
    global $products;
    if ($quantity < 1) {
        return;
    }
    // If item already exists in cart, update quantity
    if (isset($cart[$key])) {
        $quantity += $cart[$key]['qty'];
        update_item($cart, $key, $quantity);
        return;
    }
    // Add item
    $cost = $products[$key]['cost'];
    $total = $cost * $quantity;
    $item = array('name' => $products[$key]['name'], 'cost' => $cost, 'qty' => $quantity, 'total' => $total);
    $cart[$key] = $item;
}
Пример #5
0
 public function import()
 {
     //grab the data needed for using update_item or insert_item
     $elementTexts = $this->elementTexts();
     $itemMetadata = $this->itemMetadata();
     //avoid accidental duplications
     if ($this->record && $this->record->exists()) {
         $itemMetadata['overwriteElementTexts'] = true;
         update_item($this->record, $itemMetadata, $elementTexts);
         $this->updateItemOwner($this->record);
     } else {
         $this->record = insert_item($itemMetadata, $elementTexts);
         //dig up the correct owner information, importing the user if needed
         $this->updateItemOwner($this->record);
         $this->addOmekaApiImportRecordIdMap();
     }
     //import files after the item is there, so the file has an item id to use
     //we're also keeping track of the correspondences between local and remote
     //file ids, so we have to introduce this little inefficiency of not passing
     //the file data
     $this->importFiles($this->record);
 }
Пример #6
0
 public function unrateAction()
 {
     $db = $this->_helper->db->getTable('Ratings');
     // Allow only AJAX requests.
     if (!$this->getRequest()->isXmlHttpRequest()) {
         $this->_helper->redirector->gotoUrl('/');
     }
     $record_id = $this->_getParam('record_id');
     $user_id = $this->_getParam('user_id');
     // validation needed?
     if (isset($record_id) && isset($user_id)) {
         $this->_helper->db->getTable('Ratings')->removeRating($record_id, $user_id);
     }
     // update AVG rating
     $avgRating = $db->getAvgRating($record_id);
     // Get Item
     $item = get_record_by_id('Item', $record_id);
     // Update the average rating for this item
     $metaData = array('overwriteElementTexts' => true);
     $elementText = array('Ratings' => array('Average Rating' => array(array('text' => $avgRating, 'html' => false))));
     $itemUpdated = update_item($item, $metaData, $elementText);
 }
Пример #7
0
 public function perform()
 {
     if (!($itemIds = $this->_options['itemIds'])) {
         return;
     }
     $delete = $this->_options['delete'];
     $metadata = $this->_options['metadata'];
     $custom = $this->_options['custom'];
     foreach ($itemIds as $id) {
         $item = $this->_getItem($id);
         if ($delete == '1') {
             $item->delete();
         } else {
             foreach ($metadata as $key => $value) {
                 if ($value === '') {
                     unset($metadata[$key]);
                 }
             }
             update_item($item, $metadata);
             fire_plugin_hook('items_batch_edit_custom', array('item' => $item, 'custom' => $custom));
         }
         release_object($item);
     }
 }
Пример #8
0
             }
         }
     } else {
         $data = " menu_name = '{$i_name}', \n\t\t\t\t\t\t\tmenu_type_id = '{$i_menu_type_id}',\n\t\t\t\t\t\t\tmenu_original_price = '{$i_original_price}',\n\t\t\t\t\t\t\tmenu_margin_price = '{$i_margin_price}',\n\t\t\t\t\t\t\tmenu_price = '{$i_price}',\n\t\t\t\t\t\t\tpartner_id = '{$i_partner_id}',\n\t\t\t\t\t\t\tout_time = '{$i_out_time}'\n\t\t\t\t\t";
     }
     update($data, $id);
     header('Location: menu.php?page=list&did=2');
     break;
 case 'edit_item':
     extract($_POST);
     $id = get_isset($_GET['id']);
     $menu_id = get_isset($_GET['menu_id']);
     $i_item_id = get_isset($i_item_id);
     $i_item_qty = get_isset($i_item_qty);
     $data = " item_id = '{$i_item_id}', \n\t\t\t\t\t\t\titem_qty = '{$i_item_qty}'\n\t\t\t\t\t";
     update_item($data, $id);
     header("Location: menu.php?page=form&id={$menu_id}");
     break;
 case 'delete':
     $id = get_isset($_GET['id']);
     $path = "../img/menu/";
     $get_img_old = get_img_old($id);
     if ($get_img_old) {
         if (file_exists($path . $get_img_old)) {
             unlink($path . $get_img_old);
         }
     }
     delete($id);
     header('Location: menu.php?page=list&did=3');
     break;
 case 'delete_item':
Пример #9
0
 /**
  * Update item
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @static
  * @param array $items multidimensional array with items data
  * @return boolean
  */
 public static function update($items)
 {
     $result = false;
     $itemids = array();
     DBstart(false);
     foreach ($items as $item) {
         $result = update_item($item['itemid'], $item);
         if (!$result) {
             break;
         }
         $itemids[$result] = $result;
     }
     $result = DBend($result);
     if ($result) {
         return $itemids;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }
Пример #10
0
function db_save_httptest($httptestid, $hostid, $application, $name, $delay, $status, $agent, $macros, $steps)
{
    $history = 30;
    // TODO !!! Allow user set this parametr
    $trends = 90;
    // TODO !!! Allow user set this parametr
    if (!eregi('^([0-9a-zA-Z\\_\\.[.-.]\\$ ]+)$', $name)) {
        error("Scenario name should contain '0-9a-zA-Z_.\$ '- characters only");
        return false;
    }
    DBstart();
    if ($applicationid = DBfetch(DBselect('select applicationid from applications ' . ' where name=' . zbx_dbstr($application) . ' and hostid=' . $hostid))) {
        $applicationid = $applicationid['applicationid'];
    } else {
        $applicationid = add_application($application, $hostid);
        if (!$applicationid) {
            error('Can\'t add new application. [' . $application . ']');
            return false;
        }
    }
    if (isset($httptestid)) {
        $result = DBexecute('update httptest set ' . ' applicationid=' . $applicationid . ', name=' . zbx_dbstr($name) . ', delay=' . $delay . ',' . ' status=' . $status . ', agent=' . zbx_dbstr($agent) . ', macros=' . zbx_dbstr($macros) . ',' . ' error=' . zbx_dbstr('') . ', curstate=' . HTTPTEST_STATE_UNKNOWN . ' where httptestid=' . $httptestid);
    } else {
        $httptestid = get_dbid("httptest", "httptestid");
        if (DBfetch(DBselect('select t.httptestid from httptest t, applications a where t.applicationid=a.applicationid ' . ' and a.hostid=' . $hostid . ' and t.name=' . zbx_dbstr($name)))) {
            error('Scenario with name [' . $name . '] already exist');
            return false;
        }
        $result = DBexecute('insert into httptest' . ' (httptestid, applicationid, name, delay, status, agent, macros, curstate) ' . ' values (' . $httptestid . ',' . $applicationid . ',' . zbx_dbstr($name) . ',' . $delay . ',' . $status . ',' . zbx_dbstr($agent) . ',' . zbx_dbstr($macros) . ',' . HTTPTEST_STATE_UNKNOWN . ')');
        $test_added = true;
    }
    if ($result) {
        $httpstepids = array();
        foreach ($steps as $sid => $s) {
            if (!isset($s['name'])) {
                $s['name'] = '';
            }
            if (!isset($s['timeout'])) {
                $s['timeout'] = 15;
            }
            if (!isset($s['url'])) {
                $s['url'] = '';
            }
            if (!isset($s['posts'])) {
                $s['posts'] = '';
            }
            if (!isset($s['required'])) {
                $s['required'] = '';
            }
            if (!isset($s['status_codes'])) {
                $s['status_codes'] = '';
            }
            $result = db_save_step($hostid, $applicationid, $httptestid, $name, $s['name'], $sid + 1, $s['timeout'], $s['url'], $s['posts'], $s['required'], $s['status_codes'], $delay, $history, $trends);
            if (!$result) {
                break;
            }
            $httpstepids[$result] = $result;
        }
        if ($result) {
            /* clean unneeded steps */
            $db_steps = DBselect('select httpstepid from httpstep where httptestid=' . $httptestid);
            while ($step_data = DBfetch($db_steps)) {
                if (isset($httpstepids[$step_data['httpstepid']])) {
                    continue;
                }
                delete_httpstep($step_data['httpstepid']);
            }
        }
    }
    if ($result) {
        $monitored_items = array(array('description' => 'Download speed for scenario \'$1\'', 'key_' => 'web.test.in[' . $name . ',,bps]', 'type' => ITEM_VALUE_TYPE_FLOAT, 'units' => 'bps', 'httptestitemtype' => HTTPSTEP_ITEM_TYPE_IN), array('description' => 'Failed step of scenario \'$1\'', 'key_' => 'web.test.fail[' . $name . ']', 'type' => ITEM_VALUE_TYPE_UINT64, 'units' => '', 'httptestitemtype' => HTTPSTEP_ITEM_TYPE_LASTSTEP));
        foreach ($monitored_items as $item) {
            $item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,i.delta,i.valuemapid ' . ' from items i, httptestitem hi ' . ' where hi.httptestid=' . $httptestid . ' and hi.itemid=i.itemid ' . ' and hi.type=' . $item['httptestitemtype']));
            if (!$item_data) {
                $item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,i.delta,i.valuemapid ' . ' from items i where i.key_=' . zbx_dbstr($item['key_']) . ' and i.hostid=' . $hostid));
            }
            $item_args = array('description' => $item['description'], 'key_' => $item['key_'], 'hostid' => $hostid, 'delay' => $delay, 'type' => ITEM_TYPE_HTTPTEST, 'snmp_community' => '', 'snmp_oid' => '', 'value_type' => $item['type'], 'data_type' => ITEM_DATA_TYPE_DECIMAL, 'trapper_hosts' => 'localhost', 'snmp_port' => 161, 'units' => $item['units'], 'multiplier' => 0, 'snmpv3_securityname' => '', 'snmpv3_securitylevel' => 0, 'snmpv3_authpassphrase' => '', 'snmpv3_privpassphrase' => '', 'formula' => 0, 'logtimefmt' => '', 'delay_flex' => '', 'params' => '', 'ipmi_sensor' => '', 'applications' => array($applicationid));
            if (!$item_data) {
                $item_args['history'] = $history;
                $item_args['status'] = ITEM_STATUS_ACTIVE;
                $item_args['delta'] = 0;
                $item_args['trends'] = $trends;
                $item_args['valuemapid'] = 0;
                if (!($itemid = add_item($item_args))) {
                    $result = false;
                    break;
                }
            } else {
                $itemid = $item_data['itemid'];
                $item_args['history'] = $item_data['history'];
                $item_args['status'] = $item_data['status'];
                $item_args['delta'] = $item_data['delta'];
                $item_args['trends'] = $item_data['trends'];
                $item_args['valuemapid'] = $item_data['valuemapid'];
                if (!update_item($itemid, $item_args)) {
                    $result = false;
                    break;
                }
            }
            $httptestitemid = get_dbid('httptestitem', 'httptestitemid');
            DBexecute('delete from httptestitem where itemid=' . $itemid);
            if (!DBexecute('insert into httptestitem' . ' (httptestitemid, httptestid, itemid, type) ' . ' values (' . $httptestitemid . ',' . $httptestid . ',' . $itemid . ',' . $item['httptestitemtype'] . ')')) {
                $result = false;
                break;
            }
        }
    }
    if (!$result && isset($test_added)) {
        delete_httptest($httptestid);
    } else {
        $restult = $httptestid;
    }
    DBend($result);
    return $result;
}
Пример #11
0
        $input_error = 1;
        display_error(tr('The item name must be entered.'));
        set_focus('description');
    } elseif (strlen($_POST['NewStockID']) == 0) {
        $input_error = 1;
        display_error(tr('The item code cannot be empty'));
        set_focus('NewStockID');
    } elseif (strstr($_POST['NewStockID'], " ") || strstr($_POST['NewStockID'], "'") || strstr($_POST['NewStockID'], "+") || strstr($_POST['NewStockID'], "\"") || strstr($_POST['NewStockID'], "&")) {
        $input_error = 1;
        display_error(tr('The item code cannot contain any of the following characters -  & + OR a space OR quotes'));
        set_focus('NewStockID');
    }
    if ($input_error != 1) {
        if (!isset($_POST['New'])) {
            /*so its an existing one */
            update_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], $_POST['adjustment_account'], $_POST['assembly_account'], $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['selling'], $_POST['depending'], $_POST['barcode'], $_POST['weight'], $blob, $_POST['units']);
        } else {
            //it is a NEW part
            add_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], $_POST['units'], $_POST['mb_flag'], $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], $_POST['adjustment_account'], $_POST['assembly_account'], $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['selling'], $_POST['depending'], $_POST['barcode'], $_POST['weight'], $blob);
        }
        meta_forward($_SERVER['PHP_SELF']);
    }
}
function can_delete($stock_id)
{
    $sql = "SELECT COUNT(*) FROM stock_moves " . "WHERE stock_id='{$stock_id}'";
    $result = db_query($sql, "could not query stock moves");
    $myrow = db_fetch_row($result);
    if ($myrow[0] > 0) {
        display_error(tr('Cannot delete this item because there are stock ' . 'movements that refer to this item.'));
        return false;
Пример #12
0
 /**
  * Check simultaneous change of identifier and collection of the item.
  */
 protected function _testChangeIdentifierAndCollection()
 {
     $elementSetName = 'Dublin Core';
     $elementName = 'Identifier';
     // Create a new collection.
     $this->collection = insert_collection(array('public' => true));
     // Need to release item and to reload it.
     $itemId = $this->item->id;
     release_object($this->item);
     $this->item = get_record_by_id('Item', $itemId);
     // Update item.
     update_item($this->item, array('collection_id' => $this->collection->id, 'overwriteElementTexts' => true), array($elementSetName => array($elementName => array(array('text' => 'my_new_item_identifier', 'html' => false)))));
     $files = $this->item->getFiles();
     foreach ($files as $key => $file) {
         $this->_checkFile($file);
     }
 }
Пример #13
0
        $action = 'show_add_item';
    }
}
// Add or update cart as needed
switch ($action) {
    case 'add':
        $product_key = filter_input(INPUT_POST, 'productkey');
        $item_qty = filter_input(INPUT_POST, 'itemqty');
        add_item($product_key, $item_qty);
        include 'cart_view.php';
        break;
    case 'update':
        $new_qty_list = filter_input(INPUT_POST, 'newqty', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
        foreach ($new_qty_list as $key => $qty) {
            if ($_SESSION['cart12'][$key]['qty'] != $qty) {
                update_item($key, $qty);
            }
        }
        include 'cart_view.php';
        break;
    case 'show_cart':
        include 'cart_view.php';
        break;
    case 'show_add_item':
        include 'add_item_view.php';
        break;
    case 'empty_cart':
        unset($_SESSION['cart12']);
        include 'cart_view.php';
        break;
    case 'end_session':
Пример #14
0
 /**
  * Update item
  *
  * @param array $items
  * @return boolean
  */
 public static function update($items)
 {
     $items = zbx_toArray($items);
     $itemids = zbx_objectValues($items, 'itemid');
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('itemids' => $itemids, 'editable' => 1, 'webitems' => 1, 'extendoutput' => 1, 'preservekeys' => 1);
         $upd_items = self::get($options);
         foreach ($items as $gnum => $item) {
             if (!isset($upd_items[$item['itemid']])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSIONS);
             }
         }
         foreach ($items as $inum => $item) {
             $item_db_fields = $upd_items[$item['itemid']];
             unset($item_db_fields['lastvalue']);
             unset($item_db_fields['prevvalue']);
             unset($item_db_fields['lastclock']);
             unset($item_db_fields['prevorgvalue']);
             unset($item_db_fields['lastns']);
             if (!check_db_fields($item_db_fields, $item)) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect parameters used for Item');
             }
             $result = update_item($item['itemid'], $item);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot update item');
             }
         }
         self::EndTransaction(true, __METHOD__);
         return array('itemids' => $itemids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
 /**
  * Handle the POST for adding an item via the public form.
  *
  * Validate and save the contribution to the database.  Save the ID of the
  * new item to the session.  Redirect to the consent form.
  *
  * If validation fails, render the Contribution form again with errors.
  *
  * @param array $post POST array
  * @return bool
  */
 protected function _processForm($post)
 {
     if (!empty($post)) {
         //for the "Simple" configuration, look for the user if exists by email. Log them in.
         //If not, create the user and log them in.
         $user = current_user();
         $simple = get_option('contribution_simple');
         if (!$user && $simple) {
             $user = $this->_helper->db->getTable('User')->findByEmail($post['contribution_simple_email']);
         }
         // if still not a user, need to create one based on the email address
         if (!$user) {
             $user = $this->_createNewGuestUser($post);
             if ($user->hasErrors()) {
                 $errors = $user->getErrors()->get();
                 //since we're creating the user behind the scenes, skip username and name errors
                 unset($errors['name']);
                 unset($errors['username']);
                 foreach ($errors as $error) {
                     $this->_helper->flashMessenger($error, 'error');
                 }
                 return false;
             }
         }
         // The final form submit was not pressed.
         if (!isset($post['form-submit'])) {
             return false;
         }
         if (!$this->_validateContribution($post)) {
             return false;
         }
         $contributionTypeId = trim($post['contribution_type']);
         if ($contributionTypeId !== "" && is_numeric($contributionTypeId)) {
             $contributionType = get_db()->getTable('ContributionType')->find($contributionTypeId);
             $itemTypeId = $contributionType->getItemType()->id;
         } else {
             $this->_helper->flashMessenger(__('You must select a type for your contribution.'), 'error');
             return false;
         }
         $itemMetadata = array('public' => false, 'featured' => false, 'item_type_id' => $itemTypeId);
         $collectionId = get_option('contribution_collection_id');
         if (!empty($collectionId) && is_numeric($collectionId)) {
             $itemMetadata['collection_id'] = (int) $collectionId;
         }
         $fileMetadata = $this->_processFileUpload($contributionType);
         // This is a hack to allow the file upload job to succeed
         // even with the synchronous job dispatcher.
         if ($acl = get_acl()) {
             $acl->allow(null, 'Items', 'showNotPublic');
             $acl->allow(null, 'Collections', 'showNotPublic');
         }
         try {
             //in case we're doing Simple, create and save the Item so the owner is set, then update with the data
             $item = new Item();
             $item->setOwner($user);
             $item->save();
             $item = update_item($item, $itemMetadata, array(), $fileMetadata);
         } catch (Omeka_Validator_Exception $e) {
             $this->flashValidatonErrors($e);
             return false;
         } catch (Omeka_File_Ingest_InvalidException $e) {
             // Copying this cruddy hack
             if (strstr($e->getMessage(), "'contributed_file'")) {
                 $this->_helper->flashMessenger("You must upload a file when making a {$contributionType->display_name} contribution.", 'error');
             } else {
                 $this->_helper->flashMessenger($e->getMessage());
             }
             return false;
         } catch (Exception $e) {
             $this->_helper->flashMessenger($e->getMessage());
             return false;
         }
         $this->_addElementTextsToItem($item, $post['Elements']);
         // Allow plugins to deal with the inputs they may have added to the form.
         fire_plugin_hook('contribution_save_form', array('contributionType' => $contributionType, 'record' => $item, 'post' => $post));
         $item->save();
         //if not simple and the profile doesn't process, send back false for the error
         $this->_processUserProfile($post, $user);
         $this->_linkItemToContributedItem($item, $contributor, $post);
         $this->_sendEmailNotifications($user, $item);
         return true;
     }
     return false;
 }
 /**
  * Add a Dublin Core "Coverage" element to an item.
  *
  * @param Item $item The parent item.
  * @param string $coverage The feature coverage.
  */
 protected function _addCoverageElement($item, $coverage)
 {
     update_item($item, array(), array('Dublin Core' => array('Coverage' => array(array('text' => $coverage, 'html' => false)))));
 }
Пример #17
0
function process_edit_item()
{
    $item_id = $_POST['item_id'];
    $item_name = $_POST['item_name'];
    $item_description = $_POST['item_description'];
    if (!empty($_FILES['item_image']['name'])) {
        $image_file = wp_upload_bits($_FILES['item_image']['name'], null, @file_get_contents($_FILES['item_image']['tmp_name']));
        $image_file_name = $image_file['file'];
        $pos = strpos($image_file_name, 'upload');
        $item_image = substr_replace($image_file_name, '', 0, $pos);
    }
    $item_price = $_POST['item_price'];
    $item_type_id = $_POST['item_type_id'];
    $return = update_item($item_id, $item_name, $item_description, $item_image, $item_price, $item_type_id);
    if ($return) {
        wp_redirect(admin_url('admin.php?page=items_settings&settings-saved'));
    } else {
        wp_redirect(admin_url('admin.php?page=items_settings&error'));
    }
}
Пример #18
0
 function EndElement($parser, $name)
 {
     if (!$this->root) {
         return false;
     }
     global $USER_DETAILS;
     $data =& $this->data[$name];
     switch ($name) {
         case XML_TAG_HOST:
             if ($data['skip'] || !isset($data['hostid']) || !$data['hostid']) {
                 break;
             }
             // case
             if (!isset($data['port'])) {
                 $data['port'] = 10050;
             }
             if (!isset($data['status'])) {
                 $data['status'] = 0;
             }
             if (!isset($data['useip'])) {
                 $data['useip'] = 0;
             }
             if (!isset($data['dns'])) {
                 $data['dns'] = '';
             }
             if (!isset($data['ip'])) {
                 $data['ip'] = '';
             }
             if (!isset($data['proxy'])) {
                 $data['proxy'] = '';
             }
             if (!zbx_empty($data['proxy'])) {
                 $sql = 'SELECT hostid ' . ' FROM hosts ' . ' WHERE host=' . zbx_dbstr($data['proxy']) . ' AND status=' . HOST_STATUS_PROXY . ' AND ' . DBin_node('hostid', get_current_nodeid(false));
                 if ($host_data = DBfetch(DBselect($sql))) {
                     $data['proxy'] = $host_data['hostid'];
                 } else {
                     $data['proxy'] = 0;
                 }
             } else {
                 $data['proxy'] = 0;
             }
             if (update_host($data['hostid'], $data['name'], $data['port'], $data['status'], $data['useip'], $data['dns'], $data['ip'], $data['proxy'], $data['templates'], 'no', '', 623, -1, 2, '', '', null, $data['groups'])) {
                 info('Host [' . $data['name'] . '] updated');
             }
             break;
             // case
             // based on mod by scricca
         // case
         // based on mod by scricca
         case XML_TAG_HOSTPROFILE:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             if (!isset($data['devicetype'])) {
                 $data['devicetype'] = '';
             }
             if (!isset($data['name'])) {
                 $data['name'] = '';
             }
             if (!isset($data['os'])) {
                 $data['os'] = '';
             }
             if (!isset($data['serialno'])) {
                 $data['serialno'] = '';
             }
             if (!isset($data['tag'])) {
                 $data['tag'] = '';
             }
             if (!isset($data['macaddress'])) {
                 $data['macaddress'] = '';
             }
             if (!isset($data['hardware'])) {
                 $data['hardware'] = '';
             }
             if (!isset($data['software'])) {
                 $data['software'] = '';
             }
             if (!isset($data['contact'])) {
                 $data['contact'] = '';
             }
             if (!isset($data['location'])) {
                 $data['location'] = '';
             }
             if (!isset($data['notes'])) {
                 $data['notes'] = '';
             }
             delete_host_profile($this->data[XML_TAG_HOST]['hostid']);
             if (add_host_profile($this->data[XML_TAG_HOST]['hostid'], $data['devicetype'], $data['name'], $data['os'], $data['serialno'], $data['tag'], $data['macaddress'], $data['hardware'], $data['software'], $data['contact'], $data['location'], $data['notes'])) {
                 info('Host Profile [' . $this->data[XML_TAG_HOST]['name'] . '] updated');
             }
             break;
             // case
             //---
             // Extended profiles
         // case
         //---
         // Extended profiles
         case XML_TAG_HOSTPROFILE_EXT:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             if (!isset($data['device_alias'])) {
                 $data['device_alias'] = '';
             }
             if (!isset($data['device_type'])) {
                 $data['device_type'] = '';
             }
             if (!isset($data['device_chassis'])) {
                 $data['device_chassis'] = '';
             }
             if (!isset($data['device_os'])) {
                 $data['device_os'] = '';
             }
             if (!isset($data['device_os_short'])) {
                 $data['device_os_short'] = '';
             }
             if (!isset($data['device_hw_arch'])) {
                 $data['device_hw_arch'] = '';
             }
             if (!isset($data['device_serial'])) {
                 $data['device_serial'] = '';
             }
             if (!isset($data['device_model'])) {
                 $data['device_model'] = '';
             }
             if (!isset($data['device_tag'])) {
                 $data['device_tag'] = '';
             }
             if (!isset($data['device_vendor'])) {
                 $data['device_vendor'] = '';
             }
             if (!isset($data['device_contract'])) {
                 $data['device_contract'] = '';
             }
             if (!isset($data['device_who'])) {
                 $data['device_who'] = '';
             }
             if (!isset($data['device_status'])) {
                 $data['device_status'] = '';
             }
             if (!isset($data['device_app_01'])) {
                 $data['device_app_01'] = '';
             }
             if (!isset($data['device_app_02'])) {
                 $data['device_app_02'] = '';
             }
             if (!isset($data['device_app_03'])) {
                 $data['device_app_03'] = '';
             }
             if (!isset($data['device_app_04'])) {
                 $data['device_app_04'] = '';
             }
             if (!isset($data['device_app_05'])) {
                 $data['device_app_05'] = '';
             }
             if (!isset($data['device_url_1'])) {
                 $data['device_url_1'] = '';
             }
             if (!isset($data['device_url_2'])) {
                 $data['device_url_2'] = '';
             }
             if (!isset($data['device_url_3'])) {
                 $data['device_url_3'] = '';
             }
             if (!isset($data['device_networks'])) {
                 $data['device_networks'] = '';
             }
             if (!isset($data['device_notes'])) {
                 $data['device_notes'] = '';
             }
             if (!isset($data['device_hardware'])) {
                 $data['device_hardware'] = '';
             }
             if (!isset($data['device_software'])) {
                 $data['device_software'] = '';
             }
             if (!isset($data['ip_subnet_mask'])) {
                 $data['ip_subnet_mask'] = '';
             }
             if (!isset($data['ip_router'])) {
                 $data['ip_router'] = '';
             }
             if (!isset($data['ip_macaddress'])) {
                 $data['ip_macaddress'] = '';
             }
             if (!isset($data['oob_ip'])) {
                 $data['oob_ip'] = '';
             }
             if (!isset($data['oob_subnet_mask'])) {
                 $data['oob_subnet_mask'] = '';
             }
             if (!isset($data['oob_router'])) {
                 $data['oob_router'] = '';
             }
             if (!isset($data['date_hw_buy'])) {
                 $data['date_hw_buy'] = '';
             }
             if (!isset($data['date_hw_install'])) {
                 $data['date_hw_install'] = '';
             }
             if (!isset($data['date_hw_expiry'])) {
                 $data['date_hw_expiry'] = '';
             }
             if (!isset($data['date_hw_decomm'])) {
                 $data['date_hw_decomm'] = '';
             }
             if (!isset($data['site_street_1'])) {
                 $data['site_street_1'] = '';
             }
             if (!isset($data['site_street_2'])) {
                 $data['site_street_2'] = '';
             }
             if (!isset($data['site_street_3'])) {
                 $data['site_street_3'] = '';
             }
             if (!isset($data['site_city'])) {
                 $data['site_city'] = '';
             }
             if (!isset($data['site_state'])) {
                 $data['site_state'] = '';
             }
             if (!isset($data['site_country'])) {
                 $data['site_country'] = '';
             }
             if (!isset($data['site_zip'])) {
                 $data['site_zip'] = '';
             }
             if (!isset($data['site_rack'])) {
                 $data['site_rack'] = '';
             }
             if (!isset($data['site_notes'])) {
                 $data['site_notes'] = '';
             }
             if (!isset($data['poc_1_name'])) {
                 $data['poc_1_name'] = '';
             }
             if (!isset($data['poc_1_email'])) {
                 $data['poc_1_email'] = '';
             }
             if (!isset($data['poc_1_phone_1'])) {
                 $data['poc_1_phone_1'] = '';
             }
             if (!isset($data['poc_1_phone_2'])) {
                 $data['poc_1_phone_2'] = '';
             }
             if (!isset($data['poc_1_cell'])) {
                 $data['poc_1_cell'] = '';
             }
             if (!isset($data['poc_1_screen'])) {
                 $data['poc_1_screen'] = '';
             }
             if (!isset($data['poc_1_notes'])) {
                 $data['poc_1_notes'] = '';
             }
             if (!isset($data['poc_2_name'])) {
                 $data['poc_2_name'] = '';
             }
             if (!isset($data['poc_2_email'])) {
                 $data['poc_2_email'] = '';
             }
             if (!isset($data['poc_2_phone_1'])) {
                 $data['poc_2_phone_1'] = '';
             }
             if (!isset($data['poc_2_phone_2'])) {
                 $data['poc_2_phone_2'] = '';
             }
             if (!isset($data['poc_2_cell'])) {
                 $data['poc_2_cell'] = '';
             }
             if (!isset($data['poc_2_screen'])) {
                 $data['poc_2_screen'] = '';
             }
             if (!isset($data['poc_2_notes'])) {
                 $data['poc_2_notes'] = '';
             }
             delete_host_profile_ext($this->data[XML_TAG_HOST]['hostid']);
             if (add_host_profile_ext($this->data[XML_TAG_HOST]['hostid'], $data)) {
                 info('Host Extended Profile [' . $this->data[XML_TAG_HOST]['name'] . '] updated');
             }
             break;
             // case
             //---
         // case
         //---
         case XML_TAG_GROUP:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             $sql = 'SELECT groupid, name ' . ' FROM groups' . ' WHERE ' . DBin_node('groupid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($this->element_data);
             if (!($group = DBfetch(DBselect($sql)))) {
                 error('Missing group [' . $this->element_data . ']');
                 break;
                 // case
             }
             if (!isset($this->available_groups[$group['groupid']])) {
                 error('Group [' . $this->element_data . '] skipped - Access deny.');
                 break;
                 // case
             }
             $this->data[XML_TAG_HOST]['groups'][$group['groupid']] = $group['groupid'];
             break;
             // case
         // case
         case XML_TAG_DEPENDENCY:
             if (!isset($data['triggerid_down']) || !$data['triggerid_down']) {
                 break;
             }
             // case
             update_trigger($data['triggerid_down'], null, null, null, null, null, null, null, $data['triggerid_up'], null);
             break;
             // case
         // case
         case XML_TAG_DEPENDS:
             if (!isset($this->data[XML_TAG_DEPENDENCY]['triggerid_down']) || !$this->data[XML_TAG_DEPENDENCY]['triggerid_down']) {
                 break;
             }
             //case
             if (!($trigger_up = get_trigger_by_description($this->element_data))) {
                 break;
             }
             array_push($this->data[XML_TAG_DEPENDENCY]['triggerid_up'], $trigger_up['triggerid']);
             break;
             // case
         // case
         case XML_TAG_APPLICATION:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             if (!isset($this->data[XML_TAG_ITEM])) {
                 break;
             }
             //case
             $sql = 'SELECT applicationid ' . ' FROM applications' . ' WHERE ' . DBin_node('applicationid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($this->element_data) . ' AND hostid=' . $this->data[XML_TAG_HOST]['hostid'];
             if (!($application = DBfetch(DBselect($sql)))) {
                 $applicationid = add_application($this->element_data, $this->data[XML_TAG_HOST]['hostid']);
             } else {
                 $applicationid = $application['applicationid'];
             }
             $this->data[XML_TAG_ITEM]['applications'][] = $applicationid;
             break;
             // case
         // case
         case XML_TAG_TEMPLATE:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 break;
             }
             //case
             $sql = 'SELECT DISTINCT host, hostid ' . ' FROM hosts' . ' WHERE ' . DBin_node('hostid') . ' AND host=' . zbx_dbstr($this->element_data) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')';
             if (!($template = DBfetch(DBselect($sql)))) {
                 error('Missing template [' . $this->element_data . ']');
                 break;
                 // case
             }
             if (!isset($this->available_hosts[$template['hostid']])) {
                 error('Template [' . $this->element_data . '] skipped - Access deny.');
                 break;
                 // case
             }
             $this->data[XML_TAG_HOST]['templates'][$template["hostid"]] = $template['host'];
             break;
             // case
         // case
         case XML_TAG_ITEM:
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) {
                     info('Item [' . $data['description'] . '] skipped - user rule for host');
                     break;
                     // case
                 }
                 error('Item [' . $data['description'] . '] skipped - missing host');
                 break;
                 // case
             }
             if (!isset($data['description'])) {
                 $data['description'] = '';
             }
             if (!isset($data['delay'])) {
                 $data['delay'] = 30;
             }
             if (!isset($data['history'])) {
                 $data['history'] = 90;
             }
             if (!isset($data['trends'])) {
                 $data['trends'] = 365;
             }
             if (!isset($data['status'])) {
                 $data['status'] = 0;
             }
             if (!isset($data['units'])) {
                 $data['units'] = '';
             }
             if (!isset($data['multiplier'])) {
                 $data['multiplier'] = 0;
             }
             if (!isset($data['delta'])) {
                 $data['delta'] = 0;
             }
             if (!isset($data['formula'])) {
                 $data['formula'] = '';
             }
             if (!isset($data['lastlogsize'])) {
                 $data['lastlogsize'] = 0;
             }
             if (!isset($data['logtimefmt'])) {
                 $data['logtimefmt'] = '';
             }
             if (!isset($data['delay_flex'])) {
                 $data['delay_flex'] = '';
             }
             if (!isset($data['trapper_hosts'])) {
                 $data['trapper_hosts'] = '';
             }
             if (!isset($data['snmp_community'])) {
                 $data['snmp_community'] = '';
             }
             if (!isset($data['snmp_oid'])) {
                 $data['snmp_oid'] = '';
             }
             if (!isset($data['snmp_port'])) {
                 $data['snmp_port'] = 161;
             }
             if (!isset($data['snmpv3_securityname'])) {
                 $data['snmpv3_securityname'] = '';
             }
             if (!isset($data['snmpv3_securitylevel'])) {
                 $data['snmpv3_securitylevel'] = 0;
             }
             if (!isset($data['snmpv3_authpassphrase'])) {
                 $data['snmpv3_authpassphrase'] = '';
             }
             if (!isset($data['snmpv3_privpassphrase'])) {
                 $data['snmpv3_privpassphrase'] = '';
             }
             if (!isset($data['valuemap'])) {
                 $data['valuemap'] = '';
             }
             if (!isset($data['params'])) {
                 $data['params'] = '';
             }
             if (!isset($data['ipmi_sensor'])) {
                 $data['ipmi_sensor'] = '';
             }
             if (!isset($data['applications'])) {
                 $data['applications'] = array();
             }
             if (!empty($data['valuemap'])) {
                 $sql = 'SELECT valuemapid ' . ' FROM valuemaps ' . ' WHERE ' . DBin_node('valuemapid', get_current_nodeid(false)) . ' AND name=' . zbx_dbstr($data['valuemap']);
                 if ($valuemap = DBfetch(DBselect($sql))) {
                     $data['valuemapid'] = $valuemap['valuemapid'];
                 } else {
                     $data['valuemapid'] = add_valuemap($data['valuemap'], array());
                 }
             }
             $sql = 'SELECT itemid,valuemapid,templateid ' . ' FROM items ' . ' WHERE key_=' . zbx_dbstr($data['key']) . ' AND hostid=' . $this->data[XML_TAG_HOST]['hostid'] . ' AND ' . DBin_node('itemid', get_current_nodeid(false));
             if ($item = DBfetch(DBselect($sql))) {
                 /* exist */
                 if ($this->item['exist'] == 1) {
                     info('Item [' . $data['description'] . '] skipped - user rule');
                     break;
                 }
                 if (!isset($data['valuemapid'])) {
                     $data['valuemapid'] = $item['valuemapid'];
                 }
                 $data['key_'] = $data['key'];
                 $data['hostid'] = $this->data[XML_TAG_HOST]['hostid'];
                 $data['applications'] = array_unique(array_merge($data['applications'], get_applications_by_itemid($item['itemid'])));
                 $data['templateid'] = $item['templateid'];
                 check_db_fields($item, $data);
                 update_item($item['itemid'], $data);
             } else {
                 /* missed */
                 if ($this->item['missed'] == 1) {
                     info('Item [' . $data['description'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 if (!isset($data['valuemapid'])) {
                     $data['valuemapid'] = 0;
                 }
                 $data['hostid'] = $this->data[XML_TAG_HOST]['hostid'];
                 $data['key_'] = $data['key'];
                 add_item($data);
             }
             break;
             // case
         // case
         case XML_TAG_TRIGGER:
             if (!isset($data['expression'])) {
                 $data['expression'] = '';
             }
             if (!isset($data['description'])) {
                 $data['description'] = '';
             }
             if (!isset($data['type'])) {
                 $data['type'] = 0;
             }
             if (!isset($data['priority'])) {
                 $data['priority'] = 0;
             }
             if (!isset($data['status'])) {
                 $data['status'] = 0;
             }
             if (!isset($data['comments'])) {
                 $data['comments'] = '';
             }
             if (!isset($data['url'])) {
                 $data['url'] = '';
             }
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) {
                     // remember skipped triggers for dependencies
                     $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                     info('Trigger [' . $data['description'] . '] skipped - user rule for host');
                     break;
                     // case
                 }
                 if (zbx_strstr($data['expression'], '{HOSTNAME}')) {
                     // remember skipped triggers for dependencies
                     $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                     error('Trigger [' . $data['description'] . '] skipped - missing host');
                     break;
                     // case
                 }
             } else {
                 $data['expression'] = str_replace('{{HOSTNAME}:', '{' . $this->data[XML_TAG_HOST]['name'] . ':', $data['expression']);
                 $result = DBselect('SELECT DISTINCT t.triggerid,t.templateid,t.expression ' . ' FROM triggers t,functions f,items i ' . ' WHERE t.triggerid=f.triggerid ' . ' AND f.itemid=i.itemid' . ' AND i.hostid=' . $this->data[XML_TAG_HOST]['hostid'] . ' AND t.description=' . zbx_dbstr($data['description']));
                 while ($trigger = DBfetch($result)) {
                     if (explode_exp($trigger['expression'], 0) == $data['expression']) {
                         break;
                         // while
                     }
                 }
                 if (!empty($trigger)) {
                     /* exist */
                     if ($this->trigger['exist'] == 1) {
                         /* skip */
                         // remember skipped triggers for dependencies
                         $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                         info('Trigger [' . $data['description'] . '] skipped - user rule');
                         break;
                         // case
                     }
                     update_trigger($trigger['triggerid'], $data['expression'], $data['description'], $data['type'], $data['priority'], $data['status'], $data['comments'], $data['url'], get_trigger_dependencies_by_triggerid($trigger['triggerid']), $trigger['templateid']);
                     break;
                     // case
                 } else {
                     /* missed */
                     // continue [add_trigger]
                 }
             }
             if ($this->trigger['missed'] == 1) {
                 // remember skipped triggers for dependencies
                 $this->data[XML_TAG_DEPENDENCIES]['skip'][] = $this->data[XML_TAG_HOST]['name'] . ':' . $data['description'];
                 info('Trigger [' . $data['description'] . '] skipped - user rule');
                 break;
                 // case
             }
             add_trigger($data['expression'], $data['description'], $data['type'], $data['priority'], $data['status'], $data['comments'], $data['url']);
             break;
             // case
         // case
         case XML_TAG_GRAPH:
             if (isset($data['error'])) {
                 error('Graph [' . $data['name'] . '] skipped - error occured');
                 break;
                 // case
             }
             if (!isset($data['ymin_type'])) {
                 $data['ymin_type'] = 0;
             }
             if (!isset($data['ymax_type'])) {
                 $data['ymax_type'] = 0;
             }
             if (!isset($data['ymin_item_key'])) {
                 $data['ymin_item_key'] = '';
             }
             if (!isset($data['ymax_item_key'])) {
                 $data['ymax_item_key'] = '';
             }
             if (!isset($data['ymin_itemid'])) {
                 $data['ymin_itemid'] = 0;
             }
             if (!isset($data['ymax_itemid'])) {
                 $data['ymax_itemid'] = 0;
             }
             if (!isset($data['show_work_period'])) {
                 $data['show_work_period'] = 1;
             }
             if (!isset($data['show_triggers'])) {
                 $data['show_triggers'] = 1;
             }
             if (!isset($data['graphtype'])) {
                 $data['graphtype'] = 0;
             }
             if (!isset($data['yaxismin'])) {
                 $data['yaxismin'] = 0;
             }
             if (!isset($data['yaxismax'])) {
                 $data['yaxismax'] = 0;
             }
             if (!isset($data['show_legend'])) {
                 $data['show_legend'] = 0;
             }
             if (!isset($data['show_3d'])) {
                 $data['show_3d'] = 0;
             }
             if (!isset($data['percent_left'])) {
                 $data['percent_left'] = 0;
             }
             if (!isset($data['percent_right'])) {
                 $data['percent_right'] = 0;
             }
             if (!isset($data['items'])) {
                 $data['items'] = array();
             }
             if (!empty($data['ymin_item_key'])) {
                 $data['ymin_item_key'] = explode(':', $data['ymin_item_key']);
                 if (count($data['ymin_item_key']) < 2) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Incorrect y min item for graph [' . $data['name'] . ']');
                     break;
                     // case
                 }
                 $data['host'] = array_shift($data['ymin_item_key']);
                 $data['ymin_item_key'] = implode(':', $data['ymin_item_key']);
                 if (!($item = get_item_by_key($data['ymin_item_key'], $data['host']))) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Missed item [' . $data['ymin_item_key'] . '] for host [' . $data['host'] . ']');
                     break;
                     // case
                 }
                 $data['ymin_itemid'] = $item['itemid'];
             }
             if (!empty($data['ymax_item_key'])) {
                 $data['ymax_item_key'] = explode(':', $data['ymax_item_key']);
                 if (count($data['ymax_item_key']) < 2) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Incorrect y max item for graph [' . $data['name'] . ']');
                     break;
                     // case
                 }
                 $data['host'] = array_shift($data['ymax_item_key']);
                 $data['ymax_item_key'] = implode(':', $data['ymax_item_key']);
                 if (!($item = get_item_by_key($data['ymax_item_key'], $data['host']))) {
                     $this->data[XML_TAG_GRAPH]['error'] = true;
                     error('Missed item [' . $data['ymax_item_key'] . '] for host [' . $data['host'] . ']');
                     break;
                     // case
                 }
                 $data['ymax_itemid'] = $item['itemid'];
             }
             if (!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']) {
                 if (isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']) {
                     info('Graph [' . $data['name'] . '] skipped - user rule for host');
                     break;
                     // case
                 }
                 foreach ($data['items'] as $id) {
                     if (zbx_strstr($data['name'], '{HOSTNAME}')) {
                         error('Graph [' . $data['name'] . '] skipped - missing host');
                         break;
                         // case
                     }
                 }
             } else {
                 if ($graph = DBfetch(DBselect('SELECT DISTINCT g.graphid, g.templateid' . ' FROM graphs g, graphs_items gi, items i' . ' WHERE g.graphid=gi.graphid ' . ' AND gi.itemid=i.itemid' . ' AND g.name=' . zbx_dbstr($data['name']) . ' AND i.hostid=' . $this->data[XML_TAG_HOST]['hostid']))) {
                     /* exist */
                     if ($this->graph['exist'] == 1) {
                         /* skip */
                         info('Graph [' . $data['name'] . '] skipped - user rule');
                         break;
                         // case
                     }
                     $data['graphid'] = $graph['graphid'];
                     update_graph_with_items($data['graphid'], $data['name'], $data['width'], $data['height'], $data['ymin_type'], $data['ymax_type'], $data['yaxismin'], $data['yaxismax'], $data['ymin_itemid'], $data['ymax_itemid'], $data['show_work_period'], $data['show_triggers'], $data['graphtype'], $data['show_legend'], $data['show_3d'], $data['percent_left'], $data['percent_right'], $data['items'], $graph['templateid']);
                 } else {
                     /* missed */
                     // continue [add_group]
                 }
             }
             if (!isset($data['graphid'])) {
                 if ($this->graph['missed'] == 1) {
                     /* skip */
                     info('Graph [' . $data['name'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 $data['graphid'] = add_graph_with_items($data['name'], $data['width'], $data['height'], $data['ymin_type'], $data['ymax_type'], $data['yaxismin'], $data['yaxismax'], $data['ymin_itemid'], $data['ymax_itemid'], $data['show_work_period'], $data['show_triggers'], $data['graphtype'], $data['show_legend'], $data['show_3d'], $data['percent_left'], $data['percent_right'], $data['items']);
             }
             break;
             // case
         // case
         case XML_TAG_GRAPH_ELEMENT:
             if (!isset($this->data[XML_TAG_GRAPH])) {
                 break;
             }
             // case
             $data['key'] = explode(':', $data['item']);
             if (count($data['key']) < 2) {
                 $this->data[XML_TAG_GRAPH]['error'] = true;
                 error('Incorrect element for graph [' . $data['name'] . ']');
                 break;
                 // case
             }
             $data['host'] = array_shift($data['key']);
             $data['key'] = implode(':', $data['key']);
             if (isset($this->data[XML_TAG_HOST]['name'])) {
                 $data['host'] = str_replace('{HOSTNAME}', $this->data[XML_TAG_HOST]['name'], $data['host']);
             }
             if (!isset($data['drawtype'])) {
                 $data['drawtype'] = 0;
             }
             if (!isset($data['sortorder'])) {
                 $data['sortorder'] = 0;
             }
             if (!isset($data['color'])) {
                 $data['color'] = 'Dark Green';
             }
             if (!isset($data['yaxisside'])) {
                 $data['yaxisside'] = 1;
             }
             if (!isset($data['calc_fnc'])) {
                 $data['calc_fnc'] = 2;
             }
             if (!isset($data['type'])) {
                 $data['type'] = 0;
             }
             if (!isset($data['periods_cnt'])) {
                 $data['periods_cnt'] = 5;
             }
             if (!($item = get_item_by_key($data['key'], $data['host']))) {
                 $this->data[XML_TAG_GRAPH]['error'] = true;
                 error('Missing item [' . $data['key'] . '] for host [' . $data['host'] . ']');
                 break;
                 // case
             }
             $data['itemid'] = $item['itemid'];
             array_push($this->data[XML_TAG_GRAPH]['items'], $data);
             break;
             // case
             /*case XML_TAG_SCREEN:
             		case XML_TAG_SCREEN_ELEMENT:
             			break; // case*/
         // case
         /*case XML_TAG_SCREEN:
         		case XML_TAG_SCREEN_ELEMENT:
         			break; // case*/
         default:
             if (isset($this->sub_node) && isset($this->main_node)) {
                 $main_node = array_pop($this->main_node);
                 $this->data[$main_node][$this->sub_node] = $this->element_data;
                 array_push($this->main_node, $main_node);
             }
             $this->sub_node = null;
             return;
     }
     unset($this->data[$name], $data);
     array_pop($this->main_node);
 }
Пример #19
0
 /**
  * Update metadata and extra data to an existing record.
  *
  * @param Record $record An existing and checked record object.
  * @param array $document A normalized document.
  * @return Record|boolean The updated record or false if error.
  */
 protected function _updateRecord($record, $document)
 {
     // Check action.
     $action = $document['process']['action'];
     if (!in_array($action, array(ArchiveFolder_Importer::ACTION_UPDATE, ArchiveFolder_Importer::ACTION_ADD, ArchiveFolder_Importer::ACTION_REPLACE))) {
         $message = __('Only update actions are allowed here, not "%s".', $action);
         throw new ArchiveFolder_ImporterException($message);
     }
     $recordType = get_class($record);
     if ($document['process']['record type'] != $recordType) {
         $message = __('The record type "%s" is not the same than the record to update ("%s").', $document['process']['record type'], $recordType);
         throw new ArchiveFolder_ImporterException($message);
     }
     // The Builder doesn't allow action "Update", only "Add" and "Replace",
     // and it doesn't manage file directly.
     // Prepare element texts.
     $elementTexts = $document['metadata'];
     // Trim metadata to avoid spaces.
     $elementTexts = $this->_trimElementTexts($elementTexts);
     // Keep only the non empty metadata to avoid removing them with Omeka
     // methods, and to allow update.
     if ($action == ArchiveFolder_Importer::ACTION_ADD || $action == ArchiveFolder_Importer::ACTION_REPLACE) {
         $elementTexts = $this->_removeEmptyElements($elementTexts);
     }
     // Overwrite existing element text values if wanted.
     if ($action == ArchiveFolder_Importer::ACTION_UPDATE || $action == ArchiveFolder_Importer::ACTION_REPLACE) {
         $elementsToDelete = array();
         foreach ($elementTexts as $elementSetName => $elements) {
             foreach ($elements as $elementName => $elementTexts) {
                 $element = $this->_getElementFromIdentifierField($elementSetName . ':' . $elementName);
                 if ($element) {
                     $elementsToDelete[] = $element->id;
                 }
             }
         }
         if ($elementsToDelete) {
             $record->deleteElementTextsbyElementId($elementsToDelete);
         }
     }
     // Update the specific metadata and the element texts.
     // Update is different for each record type.
     switch ($recordType) {
         case 'Item':
             // Check and create collection if needed.
             // TODO Add an option to create or not a default collection.
             $collection = null;
             if (!empty($document['specific']['collection'])) {
                 $collection = $this->_createCollectionFromIdentifier($document['specific']['collection']);
                 $document['specific'][Builder_Item::COLLECTION_ID] = $collection->id;
                 unset($document['specific']['collection']);
             }
             // Update specific data of the item.
             switch ($action) {
                 case ArchiveFolder_Importer::ACTION_UPDATE:
                     // The item type is cleaned: only the name is available,
                     // if any.
                     if (empty($document['specific'][Builder_Item::ITEM_TYPE_NAME])) {
                         // TODO Currently, item type cannot be reset.
                         // $recordMetadata[Builder_Item::ITEM_TYPE_NAME] = null;
                         unset($document['specific'][Builder_Item::ITEM_TYPE_NAME]);
                     }
                     break;
                 case ArchiveFolder_Importer::ACTION_ADD:
                 case ArchiveFolder_Importer::ACTION_REPLACE:
                     if (empty($document['specific'][Builder_Item::COLLECTION_ID])) {
                         $document['specific'][Builder_Item::COLLECTION_ID] = $record->collection_id;
                     }
                     if (empty($document['specific'][Builder_Item::ITEM_TYPE_NAME])) {
                         if (!empty($record->item_type_id)) {
                             $document['specific'][Builder_Item::ITEM_TYPE_ID] = $record->item_type_id;
                         }
                         unset($document['specific'][Builder_Item::ITEM_TYPE_NAME]);
                     }
                     break;
             }
             if (empty($document['specific'][Builder_Item::TAGS])) {
                 unset($document['specific'][Builder_Item::TAGS]);
             }
             $record = update_item($record, $document['specific'], $document['metadata']);
             break;
         case 'File':
             $record->addElementTextsByArray($document['metadata']);
             $record->save();
             break;
         case 'Collection':
             $record = update_collection($record, $document['specific'], $document['metadata']);
             break;
         default:
             $message = __('Record type "%s" is not allowed.', $recordType);
             throw new ArchiveFolder_ImporterException($message);
     }
     // Update the extra metadata.
     $this->_setExtraData($record, $document['extra'], $action);
     $this->_archiveRecord($record, $document['process']['index'], $document['process']['name']);
     return $record;
 }
Пример #20
0
     }
     update($data, $id);
     $data_building = "building_name = '{$i_name}'";
     update_building($data_building, $id);
     // edit list menu
     $query_menu = mysql_query("select a.*, b.menu_type_name\n                                                from menus a    \n                                                join menu_types b on b.menu_type_id = a.menu_type_id\n                                                order by menu_id");
     while ($row_menu = mysql_fetch_array($query_menu)) {
         $i_check = isset($_POST['i_check_' . $row_menu['menu_id']]) ? $_POST['i_check_' . $row_menu['menu_id']] : "";
         if ($i_check) {
             $check_exist = check_exist($id, $row_menu['menu_id']);
             if ($check_exist == 0) {
                 $data = "'',\n\t\t\t\t\t\t\t\t\t'{$id}',\n\t\t\t\t\t\t\t\t\t'" . $row_menu['menu_id'] . "',\n\t\t\t\t\t\t\t\t\t'" . $_POST['i_branch_menu_price_' . $row_menu['menu_id']] . "'\n\t\t\t\t\t\t\t";
                 create_item($data);
             } else {
                 $get_exist = get_exist($id, $row_menu['menu_id']);
                 update_item($_POST['i_branch_menu_price_' . $row_menu['menu_id']], $get_exist);
             }
         } else {
             //echo "gagal"."<br>";
             delete_item($id, $row_menu['menu_id']);
         }
     }
     header('Location: branch.php?page=list&did=2');
     break;
 case 'delete':
     $id = get_isset($_GET['id']);
     $path = "../img/branch/";
     $get_img_old = get_img_old($id);
     if ($get_img_old) {
         if (file_exists($path . $get_img_old)) {
             unlink("../img/branch/" . $path . $get_img_old);
Пример #21
0
 /**
  * Convenience method for inserting an item and its files.
  * 
  * Method used by map writers that encapsulates item and file insertion. 
  * Items are inserted first, then files are inserted individually. This is 
  * done so Item and File objects can be released from memory, avoiding 
  * memory allocation issues.
  * 
  * @see insert_item()
  * @see insert_files_for_item()
  * @param OaipmhHarvester_Record $itemId ID of item to update
  * @param mixed $elementTexts The item's element texts
  * @param mixed $fileMetadata The item's file metadata
  * @return true
  */
 protected final function _updateItem($record, $elementTexts = array(), $fileMetadata = array())
 {
     // Update the item
     $item = update_item($record->item_id, array('overwriteElementTexts' => true), $elementTexts, $fileMetadata);
     // Update the datestamp stored in the database for this record.
     $this->_updateRecord($record);
     // Release the Item object from memory.
     release_object($item);
     return true;
 }
Пример #22
0
function add_item($key, $quantity)
{
    global $db;
    $products = get_products();
    if ($quantity < 1) {
        return;
    }
    // If item already exists in cart, update quantity
    if (isset($_SESSION['cart'][$key])) {
        $quantity += $_SESSION['cart'][$key]['qty'];
        update_item($key, $quantity);
        return;
    }
    $cost = $products[$key]['Price'];
    $total = $cost * $quantity;
    $item = array('Plant_Name' => $products[$key]['Plant_Name'], 'Price' => $cost, 'qty' => $quantity, 'total' => $total);
    $_SESSION['cart'][$key] = $item;
}
Пример #23
0
// | as published by the Free Software Foundation; either version 2           |
// | of the License, or (at your option) any later version.                   |
// |                                                                          |
// | This program is distributed in the hope that it will be useful,          |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            |
// | GNU General Public License for more details.                             |
// |                                                                          |
// | You should have received a copy of the GNU General Public License        |
// | along with this program; if not, write to the Free Software Foundation,  |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.          |
// |                                                                          |
// +--------------------------------------------------------------------------+
require_once $_CONF['path_html'] . "/fckeditor/fckeditor.php";
if (isset($_POST['update_item'])) {
    $error = update_item(basename($_FILES['picture_small']['name']), basename($_FILES['picture_large']['name']));
} else {
    if (isset($_POST['add_item'])) {
        $error = add_item(basename($_FILES['picture_small']['name']), basename($_FILES['picture_large']['name']));
    } else {
        if (isset($_POST['add_catagory'])) {
            $error = add_catagory();
        } else {
            if (isset($_GET['delete_cat'])) {
                $error = delete_catagory();
            } else {
                $error = "";
            }
        }
    }
}
Пример #24
0
 /**
  * Adds metadata and extra data to an existing record.
  *
  * @param Record $record An existing and checked record object.
  * @param string $action Allowed actions are "Update", "Add" and "Replace".
  *
  * @return Record|boolean
  * The updated record or false if metadata can't be updated.
  */
 protected function _updateRecord($record, $action = CsvImport_ColumnMap_Action::DEFAULT_ACTION)
 {
     $map =& $this->_currentMap;
     // Check action.
     if (!in_array($action, array(CsvImport_ColumnMap_Action::ACTION_UPDATE, CsvImport_ColumnMap_Action::ACTION_ADD, CsvImport_ColumnMap_Action::ACTION_REPLACE))) {
         return false;
     }
     $recordType = get_class($record);
     // Builder doesn't allow action "Update", only add and replace, and
     // doesn't manage file directly.
     // Prepare element texts.
     $elementTexts = $map[CsvImport_ColumnMap::TYPE_ELEMENT];
     // Trim metadata to avoid spaces.
     $elementTexts = $this->_trimElementTexts($elementTexts);
     // Keep only non empty fields to avoid removing them to allow update.
     if ($action == CsvImport_ColumnMap_Action::ACTION_ADD || $action == CsvImport_ColumnMap_Action::ACTION_REPLACE) {
         $elementTexts = array_values(array_filter($elementTexts, 'self::_removeEmptyElement'));
     }
     // Overwrite existing element text values if wanted.
     if ($action == CsvImport_ColumnMap_Action::ACTION_UPDATE || $action == CsvImport_ColumnMap_Action::ACTION_REPLACE) {
         foreach ($elementTexts as $key => $content) {
             if ($content['element_id']) {
                 $record->deleteElementTextsbyElementId((array) $content['element_id']);
             }
         }
     }
     // To reset keys is needed to avoid bug when there is no DC Title.
     $elementTexts = array_values($elementTexts);
     // Update the specific metadata and the element texts.
     // Update is different for each record type.
     switch ($recordType) {
         case 'Item':
             $recordMetadata = $this->_getItemMetadataFromMappedRow();
             // Create collection if needed.
             $collectionId = $this->_getMappedValue(CsvImport_ColumnMap::TYPE_COLLECTION);
             if (!empty($collectionId) && empty($recordMetadata[Builder_Item::COLLECTION_ID])) {
                 $collection = $this->_createRecordFromIdentifier($collectionId, 'Collection', $this->_defaultValues['IdentifierField']);
                 if ($collection) {
                     $recordMetadata[Builder_Item::COLLECTION_ID] = $collection->id;
                 }
             }
             // Update specific data of the item.
             switch ($action) {
                 case CsvImport_ColumnMap_Action::ACTION_UPDATE:
                     if (empty($recordMetadata[Builder_Item::ITEM_TYPE_ID]) || empty($recordMetadata[Builder_Item::ITEM_TYPE_NAME])) {
                         // TODO Currently, item type cannot be reset.
                         // $recordMetadata[Builder_Item::ITEM_TYPE_ID] = null;
                         unset($recordMetadata[Builder_Item::ITEM_TYPE_ID]);
                         unset($recordMetadata[Builder_Item::ITEM_TYPE_NAME]);
                     }
                     break;
                 case CsvImport_ColumnMap_Action::ACTION_ADD:
                 case CsvImport_ColumnMap_Action::ACTION_REPLACE:
                     if (empty($recordMetadata[Builder_Item::COLLECTION_ID])) {
                         $recordMetadata[Builder_Item::COLLECTION_ID] = $record->collection_id;
                     }
                     if (empty($recordMetadata[Builder_Item::ITEM_TYPE_ID])) {
                         $recordMetadata[Builder_Item::ITEM_TYPE_ID] = $record->item_type_id;
                     }
                     if (empty($recordMetadata[Builder_Item::ITEM_TYPE_NAME])) {
                         if (!empty($record->item_type_id)) {
                             $recordMetadata[Builder_Item::ITEM_TYPE_ID] = $record->item_type_id;
                         }
                         unset($recordMetadata[Builder_Item::ITEM_TYPE_NAME]);
                     }
                     break;
             }
             if (empty($recordMetadata[Builder_Item::TAGS])) {
                 unset($recordMetadata[Builder_Item::TAGS]);
             }
             $record = update_item($record, $recordMetadata, $elementTexts);
             break;
         case 'File':
             $record->addElementTextsByArray($elementTexts);
             $record->save();
             break;
         case 'Collection':
             $recordMetadata = $this->_getCollectionMetadataFromMappedRow();
             $record = update_collection($record, $recordMetadata, $elementTexts);
             break;
         default:
             return false;
     }
     // Update the extra metadata.
     $extraData = $map[CsvImport_ColumnMap::TYPE_EXTRA_DATA];
     $this->_setExtraData($record, $extraData, $action);
     if ($recordType == 'Item') {
         $fileUrls = $map[CsvImport_ColumnMap::TYPE_FILE];
         // Check errors for files.
         $result = $this->_updateAttachedFilesOfItem($record, $fileUrls, false, $action);
         if (!$result) {
             return false;
         }
     }
     return $record;
 }
Пример #25
0
 if (isset($_POST['report']) || isset($_POST['update'])) {
     $errors = array();
     $values = array();
     $values['item'] = $_POST['item'];
     $values[$person] = $_POST[$person];
     $values['phone'] = $_POST['phone'];
     $values['email'] = $_POST['email'];
     $values['building'] = $_POST['building'];
     $values['room'] = $_POST['room'];
     $values['description'] = $_POST['description'];
     $result = false;
     if (isset($_POST['report'])) {
         $result = insert_item($dbc, $values, $page_status);
     } else {
         $values['id'] = $_POST['id'];
         $result = update_item($dbc, $values);
     }
     # Check for any errors
     $errors = validate_values($dbc, $values);
     if ($result != false && $errors == 0) {
         # If the record was inserted successfully, redirect to the item information page
         Header("Location: /item.php?id={$result}");
     } else {
         /*
         echo 'The following errors occurred: ';
         echo "<div style='margin-left:5em'>";
         foreach($errors as $e) {
         	echo $e;
         }
         echo '</div>';
         */
Пример #26
0
<?php

$base_url = "{base url}/rest/latest/";
# Username and password should be stored according
# to your organization's security policies
$username = "******";
$password = "******";
$string_to_find = "Unique string";
$item_id = getId($string_to_find);
update_item($item_id);
function get($url)
{
    global $username, $password;
    $curl_request = curl_init();
    curl_setopt($curl_request, CURLOPT_URL, $url);
    curl_setopt($curl_request, CURLOPT_USERPWD, "{$username}:{$password}");
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, True);
    $result = curl_exec($curl_request);
    curl_close($curl_request);
    return json_decode($result, true);
}
function put($url, $payload)
{
    global $username, $password;
    $curl_request = curl_init();
    curl_setopt($curl_request, CURLOPT_URL, $url);
    curl_setopt($curl_request, CURLOPT_USERPWD, "{$username}:{$password}");
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, True);
    curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($curl_request, CURLOPT_POSTFIELDS, json_encode($payload));
    curl_setopt($curl_request, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
 public function updateAction()
 {
     $data = SELF::checkItemElement();
     $this->view->elements = $data["elements"];
     $this->view->output = $data["output"];
     $this->view->title = $data["title"];
     $this->view->elementTitle = $data["elementTitle"];
     $elements = $data["elements"];
     $output = $data["output"];
     $title = $data["title"];
     if ($elements) {
         // echo "<pre>" . print_r($_GET,true) . "</pre>";
         // echo "<pre>Elements: " . print_r($elements,true) . "</pre>";
         $itemId = intval($_GET["item"]);
         $elementId = intval($_GET["element"]);
         $order = json_decode($_GET["reorderElementTextsOrder"]);
         // echo "<pre>Order: " . print_r($order,true) . "</pre>";
         if (count($order) != count($elements)) {
             $returnLink = "<a href='javascript:window.history.back();'>" . __("Please return to the referring page.") . "</a>";
             $output .= __("Mismatching number of elements.") . " " . $returnLink;
         } else {
             $index = array();
             foreach ($elements as $idx => $element) {
                 $index[$element["id"]] = $idx;
             }
             // echo "<pre>Index: " . print_r($index,true) . "</pre>";
             $newOrder = array();
             foreach ($order as $txt) {
                 $newOrder[] = array("text" => $elements[$index[$txt]]["text"], "html" => $elements[$index[$txt]]["html"]);
             }
             // echo "<pre>NewOrder: " . print_r($newOrder,true) . "</pre>";
             $db = get_db();
             $success = true;
             # Init -- nothing done yet, so sucess ;-)
             foreach ($elements as $idx => $element) {
                 $sql = "UPDATE {$db->ElementTexts}" . " SET text='" . addslashes($newOrder[$idx]["text"]) . "'," . " html=" . $newOrder[$idx]["html"] . " WHERE id=" . $element["id"];
                 $locSuccess = $db->query($sql);
                 $success = ($success and $locSuccess);
             }
             if ($success) {
                 $this->_helper->flashMessenger(__('Reordering successful.'), 'success');
             } else {
                 $this->_helper->flashMessenger(__('Reordering failed.'), 'error');
             }
             $this->_helper->redirector($itemId, 'show', 'items');
             update_item($itemId);
         }
     }
 }
Пример #28
0
function handle_item_update(&$item_r, $HTTP_VARS, &$errors)
{
    if ($item_r['owner_id'] == get_opendb_session_var('user_id') || is_user_granted_permission(PERM_ITEM_ADMIN)) {
        if (validate_item_attributes('update', $item_r['s_item_type'], $HTTP_VARS, $errors)) {
            $fieldname = 'title';
            if (!is_array($HTTP_VARS[$fieldname])) {
                if (preg_match("/new([0-9]+)/", $HTTP_VARS[$fieldname], $matches) && isset($HTTP_VARS[$fieldname . '_' . $matches[0]])) {
                    $fieldname = $fieldname . '_' . $matches[0];
                } else {
                    if ($HTTP_VARS[$fieldname] == 'old') {
                        // make sure this is a refresh value and not just a field with the value 'old'
                        if (isset($HTTP_VARS[$fieldname . '_new0'])) {
                            $fieldname = $fieldname . '_old';
                        }
                    }
                }
            }
            // this is technically unecessary, because we enforce title as a required field.
            $item_r['title'] = ifempty($HTTP_VARS[$fieldname], $item_r['title']);
            if (update_item($item_r['item_id'], $item_r['title'])) {
                handle_item_attributes('update', $item_r, $HTTP_VARS, $errors);
                return TRUE;
            } else {
                //if(update_item($item_r['item_id'], ifempty($title_val, $item_r['title'])))
                $db_error = db_error();
                $errors = array('error' => get_opendb_lang_var('item_not_updated'), 'detail' => $db_error);
                return FALSE;
            }
        } else {
            return "__INVALID_DATA__";
        }
    } else {
        $errors = array('error' => get_opendb_lang_var('cannot_update_item_not_owned'), 'detail' => '');
        opendb_logger(OPENDB_LOG_WARN, __FILE__, __FUNCTION__, 'User attempted to update an item they do not own', $item_r);
        return FALSE;
    }
}
Пример #29
0
 */
switch ($_GET['action']) {
    case 'add_item':
        add_item();
        break;
    case 'get_items':
        get_items();
        break;
    case 'edit_product':
        edit_product();
        break;
    case 'delete_item':
        delete_item();
        break;
    case 'update_item':
        update_item();
        break;
}
function add_item()
{
    $data = json_decode(file_get_contents("php://input"));
    $suppId = mysql_real_escape_string($data->locId);
    $item = mysql_real_escape_string($data->item);
    $itemunite = mysql_real_escape_string($data->itemunite);
    $itemunitprice = mysql_real_escape_string($data->itemunitprice);
    $itemquantity = mysql_real_escape_string($data->itemquantity);
    $itemdescription = mysql_real_escape_string($data->itemdescription);
    $status = 1;
    //$upswd = mysql_real_escape_string($data->pswd);
    //$uemail = mysql_real_escape_string($data->email);
    $con = mysql_connect('localhost', 'root', '');
Пример #30
0
 public function testCanUpdateItem()
 {
     $this->item = update_item($this->item, array('public' => '1'));
     $isPublic = $this->db->fetchOne("SELECT public FROM {$this->db->Item} WHERE id = {$this->item->id}");
     $this->assertEquals(1, $isPublic, "Item should have been changed to public via update_item().");
 }