core/api/modules/magaz_cat_admin/class.php

90 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class main{
var $db; // Здесь объект для работы с MySQL
var $id;
function __construct($smarty, $settings, $db){
if ( $_SESSION['dostup'] != 'a' && $_SESSION['dostup'] != 'e')header( 'Location: /403/' );/*Если не админ - шлем в опу*/
$this->db=$db;
@mkdir(MYDIR . '/img/tc', 0700);
@mkdir(MYDIR . '/img/tc/mc', 0700);
$db->free_sql2("
CREATE TABLE IF NOT EXISTS `content` (
`id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`json` longtext NULL,
`type` varchar(50) NULL,
`parent` int NULL DEFAULT '0',
`txt` longtext NULL,
`t` varchar(11) NULL,
`public` tinyint(1) NULL DEFAULT '1'
) ENGINE='InnoDB' COLLATE 'utf8_general_ci';");
$db->free_sql2("ALTER TABLE `content` ADD `img` varchar(10) NULL;");
}
/* ------------------------------------------------------------------------------------------------------------------------- */
/* Сохраняем новую категорию */
function new_category($post, $file){
$db=$this->db;
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $file['file']['name'] ) ){
include_once ( MYDIR . '/api/php/genpass.php' );
$img_name = generate_password( 10 );
$source = $file['file']['tmp_name'];
$target = MYDIR . '/img/tc/mc/' . $img_name . '.jpg';
copy( $source, $target );
require_once MYDIR . '/api/php/img2.php';
square_preview( $target, 350, MYDIR . '/img/tc/mc/q_' . $img_name . '.jpg' );
}
//$post['img'] = $img_name;
$content['t'] = time();
$content['json'] = serialize ( $post );
$content['type'] ='mag_cat';
$content['txt'] = $post['txt'];
$content['img'] = $img_name;
$db->add('content', $content);
}
/* Сохраняем новый магазин */
function new_magazin($post, $file){
@mkdir(MYDIR . '/img/tc/magazin', 0700);
$db=$this->db;
//загружаем обложку
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $file['file']['name'] ) ){
include_once ( MYDIR . '/api/php/genpass.php' );
$img_name = generate_password( 10 );
$source = $file['file']['tmp_name'];
$target = MYDIR . '/img/tc/magazin/' . $img_name . '.jpg';
copy( $source, $target );
require_once MYDIR . '/api/php/img2.php';
square_preview( $target, 350, MYDIR . '/img/tc/magazin/q_' . $img_name . '.jpg' );
}
//загружаем логотип
if ( preg_match( '/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $file['logo']['name'] ) ){
include_once ( MYDIR . '/api/php/genpass.php' );
$logo = generate_password( 10 );
$source = $file['logo']['tmp_name'];
$target = MYDIR . '/img/tc/magazin/' . $logo . '.jpg';
copy( $source, $target );
require_once MYDIR . '/api/php/img2.php';
square_preview( $target, 350, MYDIR . '/img/tc/magazin/q_' . $logo . '.jpg' );
}
$post['img'] = $img_name;
$post['logo'] = $logo;
$content['t'] = time();
$content['json'] = serialize ( $post );
$content['type'] ='mag';
$content['txt'] = $post['txt'];
$content['img'] = $img_name;
$content['parent'] = $post['parent'];
$db->add('content', $content);
}
/* ------------------------------------------------------------------------------------------------------------------------- */
}
?>