Пример #1
0
 function loadList()
 {
     $list = loadList(STRUCTURE);
     $this->RESULT['list'] = array();
     if (!empty($_POST['field']) && isset($_POST['value'])) {
         foreach ($list as $id => $row) {
             if (!empty($row[$_POST['field']]) && $row[$_POST['field']] == $_POST['value']) {
                 $this->RESULT['list'][] = array('id' => $id, 'name' => is_array($row) ? $row['name'] : $row);
             }
         }
     } else {
         foreach ($list as $id => $row) {
             $this->RESULT['list'][] = array('id' => $id, 'name' => is_array($row) ? $row['name'] : $row);
         }
     }
 }
Пример #2
0
 /**
  * Обработчик действия: Отправка сообщения.
  */
 function sendMessage()
 {
     if (empty($_REQUEST['captcha']) || md5(strtolower($_REQUEST['captcha'])) != A_Session::get('captcha')) {
         $this->errors['captcha'] = true;
         return false;
     }
     A_Session::unregister('captcha');
     $mail = new A_Mail(A::$OPTIONS['template'], "html");
     if (!empty($_REQUEST['email'])) {
         $mail->setFrom($_REQUEST['email'], !empty($_REQUEST['name']) ? $_REQUEST['name'] : '');
     }
     $mail->Assign("data", $_REQUEST);
     $fields = array();
     A::$DB->query("SELECT * FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' ORDER BY sort");
     while ($row = A::$DB->fetchRow()) {
         if ($row['type'] == "select" || $row['type'] == "mselect") {
             $row['options'] = loadList($row['property']);
             if ($row['type'] == "mselect") {
                 $row['value'] = array();
                 $values = isset($_REQUEST[$row['field']]) ? $_REQUEST[$row['field']] : array();
                 foreach ($values as $value) {
                     $row['value'][] = isset($row['options'][$value]) ? is_array($row['options'][$value]) ? $row['options'][$value]['name'] : $row['options'][$value] : "";
                 }
                 $row['value'] = implode(", ", $row['value']);
             } else {
                 $row['value'] = isset($_REQUEST[$row['field']]) ? (int) $_REQUEST[$row['field']] : 0;
                 $row['value'] = isset($row['options'][$row['value']]) ? $row['options'][$row['value']] : "";
                 if (is_array($row['value'])) {
                     $row['data'] = $row['value'];
                     $row['value'] = !empty($row['data']['name']) ? $row['data']['name'] : "";
                 }
             }
         } elseif ($row['type'] == "file") {
             if (isset($_FILES[$row['field']]['tmp_name']) && is_file($_FILES[$row['field']]['tmp_name'])) {
                 $mail->addAttachment($_FILES[$row['field']]['tmp_name'], $_FILES[$row['field']]['name'], $_FILES[$row['field']]['type']);
             }
         } else {
             $row['value'] = isset($_REQUEST[$row['field']]) ? strip_tags($_REQUEST[$row['field']]) : "";
         }
         if ($row['type'] == "float") {
             $row['value'] = round($row['value'], 2);
         }
         $row['name'] = $row['name_' . LANG];
         $fields[$row['field']] = $row;
     }
     A::$DB->free();
     $mail->Assign("fields", $fields);
     if (isset($fields['subject'])) {
         $mail->setSubject($fields['subject']['value']);
     }
     if (isset($_REQUEST['mailto']) && isset($fields['mailto']['options'][$_REQUEST['mailto']]['email'])) {
         $mail->send($fields['mailto']['options'][$_REQUEST['mailto']]['email']);
     } elseif (!empty(A::$OPTIONS['email'])) {
         $mail->send(A::$OPTIONS['email']);
     }
     $data = array('date' => time(), 'message' => $mail->getContent(), 'data' => serialize($fields));
     if (A::$AUTH->isLogin()) {
         $data['iduser'] = A::$AUTH->id;
     }
     if ($id = A::$DB->Insert(SECTION . "_arch", $data)) {
         A_Session::set(SECTION . "_id", $id);
         A::goUrl(getSectionLink(SECTION) . "message.html");
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * Обработчик действия: Экспорт каталога.
  */
 function Export()
 {
     @set_time_limit(0);
     mk_dir("files/" . DOMAIN . "/tmp");
     clearDir("files/" . DOMAIN . "/tmp");
     require_once "Structures/DataGrid.php";
     require_once "Structures/DataGrid/DataSource/Array.php";
     require_once "Structures/DataGrid/Renderer/CSV.php";
     $categories = array();
     $fields = array();
     $all = array();
     A::$DB->query("SELECT * FROM " . SECTION . "_cols ORDER BY sort");
     $i = 0;
     while ($row = A::$DB->fetchRow()) {
         if ($row['type'] == 'select' || $row['type'] == 'mselect') {
             if ($row['idvar'] = A::$DB->getOne("SELECT property FROM " . DOMAIN . "_fields WHERE item='" . SECTION . "' AND field=?", $row['field'])) {
                 $row['vars'] = loadList($row['idvar']);
                 foreach ($row['vars'] as $j => $name) {
                     if (is_array($name) && isset($name['name'])) {
                         $row['vars'][$j] = $name['name'];
                     }
                 }
             }
         }
         $row['id'] = $i++;
         $all[$row['field']] = $row;
         if (preg_match("/^category([0-9]{1})\$/i", $row['field'], $matches)) {
             $row['level'] = $matches[1];
             $categories[$row['field']] = $row;
         } else {
             $fields[$row['field']] = $row;
         }
     }
     A::$DB->free();
     $renderer = new Structures_DataGrid_Renderer_CSV();
     $renderer->setOptions(array('delimiter' => ';', 'enclosure' => '"', 'saveToFile' => true, 'useQuotes' => true, 'filename' => "files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . ".csv"));
     $renderer->init();
     $datasource = new Structures_DataGrid_DataSource_Array();
     $datagrid = new Structures_DataGrid();
     $datagrid->bindDataSource($datasource);
     $datagrid->attachRenderer(&$renderer);
     $i = 0;
     $header = array();
     foreach ($all as $field => $frow) {
         $header[$i++] = array('field' => $field, 'label' => mb_convert_encoding($frow['caption'], "Windows-1251", "UTF-8"));
     }
     $renderer->buildHeader($header);
     $cats = array();
     $this->getCategories($cats);
     $i = 0;
     foreach ($cats as $id => $category) {
         A::$DB->query("SELECT * FROM " . SECTION . "_catalog WHERE idcat={$id} ORDER BY name");
         while ($row = A::$DB->fetchRow()) {
             $crow = array();
             for ($j = 0; $j < count($all); $j++) {
                 $crow[$j] = "";
             }
             foreach ($categories as $field => $frow) {
                 if (isset($category['parents'][$frow['level']])) {
                     $crow[$frow['id']] = mb_convert_encoding($category['parents'][$frow['level']], "Windows-1251", "UTF-8");
                 }
             }
             foreach ($fields as $field => $frow) {
                 switch ($frow['type']) {
                     default:
                         $crow[$frow['id']] = isset($row[$field]) ? mb_convert_encoding($row[$field], "Windows-1251", "UTF-8") : '';
                         break;
                     case 'select':
                         $crow[$frow['id']] = !empty($frow['vars'][$row[$field]]) ? mb_convert_encoding($frow['vars'][$row[$field]], "Windows-1251", "UTF-8") : "";
                         break;
                     case 'mselect':
                         $row[$field] = explode(',', $row[$field]);
                         foreach ($row[$field] as $j => $value) {
                             $row[$field][$j] = !empty($frow['vars'][(int) $value]) ? mb_convert_encoding($frow['vars'][(int) $value], "Windows-1251", "UTF-8") : "";
                         }
                         $crow[$frow['id']] = implode(', ', $row[$field]);
                         break;
                     case 'float':
                         $crow[$frow['id']] = round($row[$field], 2);
                         break;
                     case 'image':
                         if (preg_match("/^idimg([0-9]+)\$/i", $field, $mathes)) {
                             $sort = $mathes[1];
                             $images = A::$DB->getCol("SELECT path FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem=" . $row['id'] . " ORDER BY sort");
                             $crow[$frow['id']] = isset($images[$sort]) ? basename($images[$sort]) : "";
                         }
                         break;
                     case 'file':
                         if (preg_match("/^idfile([0-9]+)\$/i", $field, $mathes)) {
                             $sort = $mathes[1];
                             $files = A::$DB->getCol("SELECT path FROM " . DOMAIN . "_files WHERE idsec=" . SECTION_ID . " AND iditem=" . $row['id'] . " ORDER BY sort");
                             $crow[$frow['id']] = isset($files[$sort]) ? basename($files[$sort]) : "";
                         }
                         break;
                 }
             }
             if (isset($fields['mprice']) && isset($fields['price'])) {
                 $mprices = !empty($row['mprices']) ? unserialize($row['mprices']) : array();
                 foreach ($mprices as $mp) {
                     $crow[$fields['mprice']['id']] = mb_convert_encoding($mp['name'], "Windows-1251", "UTF-8");
                     $crow[$fields['price']['id']] = (double) $mp['price'];
                     $renderer->buildRow($i++, $crow);
                 }
                 if (empty($mprices)) {
                     $renderer->buildRow($i++, $crow);
                 }
             } else {
                 $renderer->buildRow($i++, $crow);
             }
         }
         A::$DB->free();
     }
     $renderer->render();
     $renderer->finalize();
     if (filesize($file = "files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . '.csv') > 1024 * 2000) {
         return outArchive("files/" . DOMAIN . "/tmp/" . DOMAIN . "_" . getName(SECTION) . ".tar.gz", $file);
     } else {
         require_once 'HTTP/Download.php';
         $params = array('file' => $file, 'contenttype' => 'text/csv', 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, basename($file)));
         HTTP_Download::staticSend($params, false);
     }
 }
function loadSite($db)
{
    return loadList($db, "Site");
}
Пример #5
0
 function Import()
 {
     require_once "Structures/DataGrid.php";
     require_once "Structures/DataGrid/DataSource/Excel.php";
     require_once "Structures/DataGrid/DataSource/CSV.php";
     require_once 'Image/Transform.php';
     A::$REGFILES = getSectionByModule('pages');
     mk_dir("files/" . DOMAIN . "/tmp");
     clearDir("files/" . DOMAIN . "/tmp");
     if (isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name'])) {
         $path_parts = pathinfo($_FILES['file']['name']);
         $ext = preg_replace("/[^a-z0-9]+/i", "", mb_strtolower($path_parts['extension']));
         if ($ext == 'xls' || $ext == 'csv') {
             if ($ext == 'csv') {
                 $sourcefile = $_FILES['file']['tmp_name'];
                 $content = @file_get_contents($sourcefile);
                 if ($content && !mb_check_encoding($content, 'UTF-8')) {
                     file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251'));
                 }
             } else {
                 $sourcefile = $_FILES['file']['tmp_name'];
             }
             if ($ext == 'xls') {
                 $datasource = new Structures_DataGrid_DataSource_Excel();
                 $datasource->bind($sourcefile);
             } elseif ($ext == 'csv') {
                 $datasource = new Structures_DataGrid_DataSource_CSV();
                 $datasource->bind($sourcefile, array('delimiter' => ';', 'enclosure' => '"'));
             } else {
                 return false;
             }
             $datagrid = new Structures_DataGrid();
             $datagrid->bindDataSource($datasource);
             if (isset($_REQUEST['clear'])) {
                 A::$DB->execute("TRUNCATE " . STRUCTURE);
             }
             $sort = A::$DB->getOne("SELECT MAX(sort) FROM " . STRUCTURE) + 1;
             $list = array();
             foreach ($datagrid->recordSet as $row) {
                 if (empty($row)) {
                     continue;
                 }
                 if ($ext == 'xls') {
                     $trow = array();
                     foreach ($row as $j => $value) {
                         if (!empty($value)) {
                             $trow[$j - 1] = $value;
                         }
                     }
                     $row = $trow;
                 }
                 $data = array();
                 if (!empty($row[0])) {
                     $data['name_' . LANG] = trim($row[0]);
                 } else {
                     continue;
                 }
                 $j = 1;
                 A::$DB->query("SELECT * FROM " . DOMAIN . "_fields WHERE item='" . STRUCTURE . "' ORDER BY sort");
                 while ($frow = A::$DB->fetchRow()) {
                     switch ($frow['type']) {
                         default:
                             $data[$frow['field']] = !empty($row[$j]) ? trim($row[$j]) : "";
                             break;
                         case 'int':
                             $data[$frow['field']] = !empty($row[$j]) ? (int) $row[$j] : 0;
                             break;
                         case 'float':
                             $data[$frow['field']] = !empty($row[$j]) ? (double) $row[$j] : 0;
                             break;
                         case 'select':
                             if (!empty($row[$j])) {
                                 if (!isset($list[$frow['property']])) {
                                     $list[$frow['property']] = loadList($frow['property']);
                                 }
                                 $row[$j] = trim($row[$j]);
                                 $key = array_search($row[$j], $list[$frow['property']]);
                                 if (empty($key) && !empty($row[$j])) {
                                     $key = addToList($frow['property'], $row[$j]);
                                     $list[$frow['property']][$key] = $row[$j];
                                 }
                                 if (!empty($key)) {
                                     $data[$frow['field']] = $key;
                                 }
                             }
                             break;
                         case 'mselect':
                             if (!empty($row[$j])) {
                                 if (!isset($list[$frow['property']])) {
                                     $list[$frow['property']] = loadList($frow['property']);
                                 }
                                 $row[$j] = explode(',', $row[$j]);
                                 $data[$frow['field']] = array();
                                 foreach ($row[$j] as $value) {
                                     $value = trim($value);
                                     $key = array_search($value, $list[$frow['property']]);
                                     if (empty($key) && !empty($value)) {
                                         $key = addToList($frow['idvar'], $value);
                                         $list[$frow['property']][$key] = $value;
                                     }
                                     if (!empty($key)) {
                                         $data[$frow['field']][] = sprintf("%04d", $key);
                                     }
                                 }
                                 $data[$frow['field']] = implode(",", $data[$frow['field']]);
                             }
                             break;
                         case 'bool':
                             $data[$frow['field']] = !empty($row[$j]) && $row[$j] != 'N' ? "Y" : "N";
                             break;
                         case 'image':
                             $row[$j] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$j]);
                             if (is_file($path = "ifiles/" . $row[$j])) {
                                 $data[$frow['field']] = RegisterImage($path, $data['name_' . LANG]);
                             }
                             break;
                         case 'file':
                             $row[$j] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$j]);
                             if (is_file($path = "ifiles/" . $row[$j])) {
                                 $data[$frow['field']] = RegisterFile($path, $data['name_' . LANG]);
                             }
                             break;
                     }
                     $j++;
                 }
                 A::$DB->free();
                 $data['sort'] = $sort++;
                 A::$DB->Insert(STRUCTURE, $data);
             }
             return true;
         }
     }
     return false;
 }
Пример #6
0
function fcategory_prepareValues($section, $data)
{
    static $structure = null;
    static $fields = array();
    static $sections = array();
    if (is_null($structure)) {
        $structure = getStructureByPlugin('fcategory');
    }
    if (!$structure) {
        return $data;
    }
    if (isset($sections[$section])) {
        $idsec = $sections[$section];
    } else {
        $idsec = $sections[$section] = getSectionId($section);
    }
    if (!isset($fields[$idsec])) {
        $fields[$idsec] = A::$DB->getAssoc("SELECT f.field,f.* FROM {$structure} AS f WHERE f.idsec={$idsec} ORDER BY sort");
        foreach ($fields[$idsec] as $field => $row) {
            if ($row['type'] == "select" || $row['type'] == "mselect") {
                $fields[$idsec][$field]['options'] = loadList($row['property']);
            }
        }
    }
    $data['fields'] = array();
    foreach ($fields[$idsec] as $field => $row) {
        if (isset($data[$field])) {
            switch ($row['type']) {
                case 'select':
                    $data[$field . '_id'] = $data[$field];
                    $data[$field] = isset($row['options'][$data[$field]]) ? $row['options'][$data[$field]] : "";
                    break;
                case 'mselect':
                    $values = explode(",", $data[$field]);
                    $options = array();
                    foreach ($values as $i => $value) {
                        $value = (int) $value;
                        if (isset($row['options'][$value])) {
                            $options[$value] = $row['options'][$value];
                            $values[$i] = is_array($row['options'][$value]) ? $row['options'][$value]['name'] : $row['options'][$value];
                        } else {
                            $values[$i] = "";
                        }
                    }
                    $data[$field] = implode(", ", $values);
                    $data[$field . '_options'] = $options;
                    break;
                case 'bool':
                    $data[$field . '_id'] = $data[$field];
                    switch ($data[$field]) {
                        case 'Y':
                            $data[$field] = "Да";
                            break;
                        case 'N':
                            $data[$field] = "Нет";
                            break;
                        default:
                            $data[$field] = "";
                    }
            }
            $data['fields'][] = array('field' => $field, 'name' => $row['name'], 'value' => is_array($data[$field]) ? $data[$field]['name'] : $data[$field]);
        }
    }
    return $data;
}
Пример #7
0
        $row[] = $date;
        $row[] = $time;
        $data[] = $row;
    }
    // Close statement object
    $stmt->close();
    return $data;
}
if (isset($_POST['action']) && !empty($_POST['action'])) {
    $action = $_POST['action'];
    switch ($action) {
        case 'getAll':
            getAll();
            break;
        case 'loadList':
            loadList();
            break;
        case 'loadUserList':
            loadUserList();
            break;
        case 'submitDay':
            submitDay($_POST['arr']);
            break;
        case 'add':
            if ($_SESSION['admin'] == TRUE) {
                add($_POST['arr']);
            } else {
                echo "FAIL";
            }
            break;
        case 'remove':