コード例 #1
0
function import_csv($csv)
{
    $error = 0;
    $create = 0;
    $update = 0;
    $error_mess = array();
    while ($tab = $csv->readLine()) {
        //init optionnal values
        $AllKeyPossible = array_merge($csv->getKeys(), $csv->getOptionalKeys());
        $tab = initArray($AllKeyPossible, $tab);
        //check
        $category = \Pasteque\CategoriesService::getByName($tab['category']);
        $taxCat = \Pasteque\TaxesService::getByName($tab['tax_cat']);
        if ($taxCat && $category) {
            $prod = readProductLine($tab, $category, $taxCat);
            $product_exist = \Pasteque\ProductsService::getByRef($prod->reference);
            if ($product_exist !== null) {
                // update product
                $prod->id = $product_exist->id;
                $prod = mergeProduct($product_exist, $prod);
                //if update imposible an is occurred
                if (!\Pasteque\ProductsService::update($prod)) {
                    $error++;
                    $error_mess[] = \i18n("On line %d: " . "Cannot update product: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['label']);
                } else {
                    // update stock_curr and stock_diary
                    manage_stock_level($prod->id, $tab, FALSE);
                    $update++;
                }
            } else {
                // create product
                $id = \Pasteque\ProductsService::create($prod);
                if ($id) {
                    //create stock_curr and stock diary
                    manage_stock_level($id, $tab, TRUE);
                    $create++;
                } else {
                    $error++;
                    $error_mess[] = \i18n("On line %d: " . "Cannot create product: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['label']);
                }
            }
        } else {
            // Missing category or tax category
            $error++;
            if (!$category) {
                $error_mess[] = \i18n("On line %d " . "category: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['category']);
            }
            if (!$taxCat) {
                $error_mess[] = \i18n("On line %d: " . "Tax category: '%s' doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['tax_cat']);
            }
        }
    }
    $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error);
    return array($message, $error_mess);
}
コード例 #2
0
ファイル: json_proxy.php プロジェクト: anxingirl/con
function returnData($total, $results, $startIndex, $sort, $dir, $sort_dir)
{
    // All records
    $allRecords = initArray($total);
    // Need to sort records
    if (!is_null($sort)) {
        // Obtain a list of columns
        foreach ($allRecords as $key => $row) {
            $sortByCol[$key] = $row[$sort];
        }
        // Valid sort value
        if (count($sortByCol) > 0) {
            // Sort the original data
            // Add $allRecords as the last parameter, to sort by the common key
            array_multisort($sortByCol, $sort_dir, $allRecords);
        }
    }
    // Invalid start value
    if (is_null($startIndex) || !is_numeric($startIndex) || $startIndex < 0 || $startIndex > count($allRecords)) {
        // Default is zero
        $startIndex = 0;
    } else {
        // Convert to number
        $startIndex += 0;
    }
    // Invalid results value
    if (is_null($results) || !is_numeric($results) || $results < 1 || $results >= count($allRecords)) {
        // Default is all
        $results = count($allRecords);
    } else {
        // Convert to number
        $results += 0;
    }
    // Iterate through records and return from start index
    $data = array();
    $lastIndex = $startIndex + $results;
    if ($lastIndex > count($allRecords)) {
        $lastIndex = count($allRecords);
    }
    for ($i = $startIndex; $i < $lastIndex; $i++) {
        $data[] = $allRecords[$i];
    }
    // Create return value
    $returnValue = array('recordsReturned' => count($data), 'totalRecords' => count($allRecords), 'startIndex' => $startIndex, 'sort' => $sort, 'dir' => $dir, 'pageSize' => $results, 'records' => $data);
    // JSONify
    //print json_encode($returnValue);
    // Use Services_JSON
    require_once 'JSON.php';
    $json = new Services_JSON();
    echo $json->encode($returnValue);
    // Instead of json_encode
}
コード例 #3
0
<?php

/* yadl_spaceid - Skip Stamping */
header('Content-type: text/plain');
$search_queries = initArray();
$query = $_GET['query'];
$results = search($search_queries, $query);
sendResults($query, $results);
function search($search_queries, $query)
{
    if (strlen($query) == 0) {
        return;
    }
    $query = strtolower($query);
    $firstChar = $query[0];
    if (!preg_match('/[0-9a-z]/', $firstChar, $matches)) {
        return;
    }
    $charQueries = $search_queries[$firstChar];
    $results = array();
    for ($i = 0; $i < count($charQueries); $i++) {
        if (strcasecmp(substr($charQueries[$i], 0, strlen($query)), $query) == 0) {
            $results[] = $charQueries[$i];
        }
    }
    return $results;
}
function sendResults($query, $results)
{
    for ($i = 0; $i < count($results); $i++) {
        print "{$results[$i]}\n";
コード例 #4
0
 /**
  * Proccess master-details
  *
  * @param array $record
  * @param array $data
  * @param Number gridRowInd
  */
 function proccessDetailGridInfo(&$record, &$data, $gridRowInd)
 {
     for ($i = 0; $i < count($this->allDetailsTablesArr); $i++) {
         $detailTableData = $this->allDetailsTablesArr[$i];
         $dDataSourceTable = $detailTableData['dDataSourceTable'];
         if ($detailTableData['dType'] == PAGE_LIST && !$this->permis[$dDataSourceTable]["search"]) {
             continue;
         }
         $dShortTable = $detailTableData['dShortTable'];
         $masterquery = "mastertable=" . rawurlencode($this->tName);
         initArray($this->controlsMap, 'gridRows');
         initArray($this->controlsMap['gridRows'], $gridRowInd);
         initArray($this->controlsMap['gridRows'][$gridRowInd], 'masterKeys');
         $this->controlsMap['gridRows'][$gridRowInd]['masterKeys'][$dDataSourceTable] = array();
         $detailid = array();
         foreach ($this->masterKeysByD[$i] as $idx => $m) {
             $curM = $m;
             if ($this->pageType == PAGE_REPORT) {
                 $curM = goodFieldName($curM);
                 $curM .= '_dbvalue';
             }
             $masterquery .= "&masterkey" . ($idx + 1) . "=" . rawurlencode($data[$curM]);
             // Don't need to use here make_db_value func, it use in countDetailsRecsNoSubQ func
             $detailid[] = $data[$curM];
             $this->controlsMap['gridRows'][$gridRowInd]['masterKeys'][$dDataSourceTable]["masterkey" . ($idx + 1)] = $data[$curM];
         }
         //	add count of child records to SQL
         if (($detailTableData['dispChildCount'] || $detailTableData['hideChild']) && !$this->isDetailTableSubquerySupported($dDataSourceTable, $i)) {
             $data[$dDataSourceTable . "_cnt"] = $this->countDetailsRecsNoSubQ($i, $detailid);
         }
         //detail tables
         $record[$dShortTable . "_dtable_link"] = $this->permis[$dDataSourceTable]['add'] || $this->permis[$dDataSourceTable]['search'];
         if ($detailTableData['dispChildCount']) {
             if ($data[$dDataSourceTable . "_cnt"] + 0) {
                 $record[$dShortTable . "_childcount"] = true;
             }
             $record[$dShortTable . "_childnumber"] = $data[$dDataSourceTable . "_cnt"];
             $record[$dShortTable . "_childnumber_attr"] = " id='cntDet_" . $dShortTable . "_" . $this->recId . "'";
             $this->controlsMap['gridRows'][$gridRowInd]['childNum'] = $data[$dDataSourceTable . "_cnt"];
         }
         if ($this->pSet->getDPType($dDataSourceTable) == DP_INLINE) {
             $record[$dShortTable . "_dtablelink_attrs"] = "id = \"" . $dShortTable . "_preview" . $this->recId . "\" \n\t\t\t\t\tcaption = \"" . runner_htmlspecialchars(GetTableCaption(GoodFieldName($dDataSourceTable))) . "\"" . "href = \"" . GetTableLink($dShortTable, $detailTableData['dType'], $masterquery) . "\"";
         } else {
             $record[$dShortTable . "_dtablelink_attrs"] = "id=\"master_" . $dShortTable . "_" . $this->recId . "\" href=\"" . GetTableLink($dShortTable, $detailTableData['dType'], $masterquery) . "\"";
         }
         if ($detailTableData['hideChild']) {
             if (!($data[$dDataSourceTable . "_cnt"] + 0)) {
                 $record[$dShortTable . "_dtablelink_attrs"] .= " class=\"" . $this->makeClassName("hiddenelem") . "\"";
             }
         }
     }
 }