예제 #1
0
 function createData()
 {
     switch ($type = getPluginByStructure($this->structure)) {
         case 'listdata':
             $sort = !empty($this->params['random']) ? 'RAND()' : 'sort';
             $limit = !empty($this->params['rows']) ? " LIMIT 0," . (int) $this->params['rows'] : "";
             $list = A::$DB->getAll("SELECT * FROM {$this->structure} ORDER BY {$sort}{$limit}");
             foreach ($list as $i => $row) {
                 $list[$i]['name'] = $row['name_' . A::$LANG];
             }
             break;
         case 'listnum':
             $sort = !empty($this->params['random']) ? 'RAND()' : 'num';
             $limit = !empty($this->params['rows']) ? " LIMIT 0," . (int) $this->params['rows'] : "";
             $list = A::$DB->getAll("SELECT * FROM {$this->structure} ORDER BY {$sort}{$limit}");
             foreach ($list as $i => $row) {
                 $list[$i]['name'] = $row['num'];
             }
             break;
         case 'liststr':
             $sort = !empty($this->params['random']) ? 'RAND()' : 'name';
             $limit = !empty($this->params['rows']) ? " LIMIT 0," . (int) $this->params['rows'] : "";
             $list = A::$DB->getAll("SELECT * FROM {$this->structure} ORDER BY {$sort}{$limit}");
             break;
     }
     $this->Assign("list", $list);
 }
예제 #2
0
function fcategory_dataset_prepare($dataset)
{
    if ($structure = getStructureByPlugin('fcategory')) {
        A::$DB->query("SELECT * FROM {$structure} WHERE idsec=" . SECTION_ID . " ORDER BY sort");
        while ($row = A::$DB->fetchRow()) {
            switch ($row['type']) {
                case "int":
                    $_REQUEST[$row['field']] = isset($_REQUEST[$row['field']]) ? (int) $_REQUEST[$row['field']] : 0;
                    $dataset->fields[] = $row['field'];
                    break;
                case "select":
                    $_REQUEST[$row['field']] = isset($_REQUEST[$row['field']]) ? (int) $_REQUEST[$row['field']] : 0;
                    $options = loadList($row['property']);
                    if (!isset($options[$_REQUEST[$row['field']]]) && !empty($_REQUEST[$row['field'] . "_txt"])) {
                        if ($string = trim($_REQUEST[$row['field'] . "_txt"])) {
                            if ($plugin = getPluginByStructure($row['property'])) {
                                if (function_exists("{$plugin}_add")) {
                                    $_REQUEST[$row['field']] = call_user_func("{$plugin}_add", $row['property'], $string);
                                }
                            }
                        }
                    }
                    $dataset->fields[] = $row['field'];
                    break;
                case "mselect":
                    if (!empty($_REQUEST[$row['field']]) && is_array($_REQUEST[$row['field']])) {
                        $values = array();
                        foreach ($_REQUEST[$row['field']] as $sid) {
                            $values[] = sprintf("%04d", (int) $sid);
                        }
                        $_REQUEST[$row['field']] = implode(",", $values);
                    } else {
                        $_REQUEST[$row['field']] = "";
                    }
                    $dataset->fields[] = $row['field'];
                    break;
                case "float":
                    $_REQUEST[$row['field']] = isset($_REQUEST[$row['field']]) ? (double) $_REQUEST[$row['field']] : 0;
                    $dataset->fields[] = $row['field'];
                    break;
                case "bool":
                    $_REQUEST[$row['field']] = isset($_REQUEST[$row['field']]) ? "Y" : "N";
                    $dataset->fields[] = $row['field'];
                    break;
                case "date":
                    $_REQUEST[$row['field']] = isset($_REQUEST[$row['field']]) ? (int) $_REQUEST[$row['field']] : mktime(0, 0, 0, (int) $_REQUEST[$row['field'] . 'Month'], (int) $_REQUEST[$row['field'] . 'Day'], (int) $_REQUEST[$row['field'] . 'Year']);
                    $dataset->fields[] = $row['field'];
                    break;
                case "string":
                case "text":
                case "format":
                    $_REQUEST[$row['field']] = isset($_REQUEST[$row['field']]) ? trim($_REQUEST[$row['field']]) : "";
                    $dataset->fields[] = $row['field'];
                    break;
                case "image":
                    if (empty(A::$REGFILES)) {
                        A::$REGFILES = getSectionByModule('pages');
                    }
                    if (empty($dataset->data) || empty($_REQUEST['parent_id'])) {
                        $_REQUEST[$row['field']] = UploadImage($row['field'], !empty($_REQUEST['name']) ? $_REQUEST['name'] : "");
                    } else {
                        $_REQUEST[$row['field']] = UploadImage($row['field'], !empty($_REQUEST['name']) ? $_REQUEST['name'] : "", $dataset->data[$row['field']]);
                        if (isset($_REQUEST[$row['field'] . '_del'])) {
                            DelRegImage($dataset->data[$row['field']]);
                            $_REQUEST[$row['field']] = 0;
                        }
                    }
                    $dataset->fields[] = $row['field'];
                    break;
                case "file":
                    if (empty(A::$REGFILES)) {
                        A::$REGFILES = getSectionByModule('pages');
                    }
                    if (empty($dataset->data) || empty($_REQUEST['parent_id'])) {
                        $_REQUEST[$row['field']] = UploadFile($row['field'], !empty($_REQUEST['name']) ? $_REQUEST['name'] : "");
                    } else {
                        $_REQUEST[$row['field']] = UploadFile($row['field'], !empty($_REQUEST['name']) ? $_REQUEST['name'] : "", $dataset->data[$row['field']]);
                        if (isset($_REQUEST[$row['field'] . '_del'])) {
                            DelRegFile($dataset->data[$row['field']]);
                            $_REQUEST[$row['field']] = 0;
                        }
                    }
                    $dataset->fields[] = $row['field'];
                    break;
            }
        }
        A::$DB->free();
    }
}