Exemplo n.º 1
0
 function on_submit()
 {
     $gfsubmit = Url::get("gfsubmit");
     if ($gfsubmit) {
         $fgroup_id = (int) implode(array_keys($gfsubmit));
         if ($fgroup_id) {
             $fgroup = DB::select("filter_group", "id={$fgroup_id}");
             if ($fgroup) {
                 $gf_name = Url::get('gf_name');
                 $gf_pos = Url::get('gf_pos');
                 if (isset($gf_name[$fgroup_id], $gf_pos[$fgroup_id]) && $gf_name[$fgroup_id] && $gf_pos[$fgroup_id]) {
                     $gf_name = $gf_name[$fgroup_id];
                     $gf_pos = $gf_pos[$fgroup_id];
                     if ($fgroup['name'] != $gf_name || $fgroup['pos'] != $gf_pos) {
                         $max_pos = (int) DB::fetch("SELECT max(pos) AS max_pos FROM filter_group", 'max_pos', 0);
                         if ($gf_pos > $max_pos) {
                             $gf_pos = $max_pos;
                         } elseif ($gf_pos <= 0) {
                             $gf_pos = $fgroup['pos'];
                         }
                         DB::update('filter_group', array("name" => $gf_name, "pos" => $gf_pos), "id={$fgroup_id}");
                         if (DB::select('filter_group', "pos={$gf_pos} AND id!={$fgroup_id}")) {
                             DB::query("UPDATE filter_group SET pos=pos+1 WHERE pos>={$gf_pos} AND pos<={$fgroup['pos']} AND id!={$fgroup_id}");
                         }
                         AZLib::getFilters(1);
                     }
                 }
             }
         }
         Url::redirect_current(array('cmd', 'id'));
     }
     $submit = Url::get("submit");
     if ($submit == "Thêm nhóm thuộc tính") {
         $gfilter_name = Url::get('gfilter_name');
         $gfilter_pos = Url::get('gfilter_pos');
         if ($gfilter_name != '' && $gfilter_pos) {
             $gfilter_group = array('name' => $gfilter_name, 'catids' => $this->cat['id'], 'pos' => $gfilter_pos);
             $max_pos = (int) DB::fetch("SELECT max(pos) AS max_pos FROM filter_group", 'max_pos', 0);
             if ($gfilter_pos > $max_pos || $gfilter_pos <= 0) {
                 $gfilter_pos = $max_pos + 1;
             }
             $gfilter_group['pos'] = $gfilter_pos;
             $id = DB::insert('filter_group', $gfilter_group);
             if ($id && DB::select('filter_group', 'pos="' . $gfilter_pos . '" AND id!=' . $id)) {
                 DB::query('UPDATE filter_group SET pos=pos+1 WHERE pos>=' . $gfilter_pos . ' AND id!=' . $id);
             }
         }
         AZLib::getFilters(1);
         Url::redirect_current(array('cmd', 'id'));
     }
     $name = Url::get('name');
     $brief_name = Url::get('brief_name');
     $keywords = Url::get('keywords');
     $description = Url::get('description');
     $parent_id = Url::get('parent_id');
     $zoneids = Url::get('zoneids');
     $ref_id = Url::get('ref_id');
     $status = Url::get('status', 'HIDE');
     $position = Url::get('position');
     $tag_search = Url::get('tag_search');
     $price_str = trim(Url::get('price_str'));
     $recomend = trim(Url::get('recomend'));
     if ($price_str) {
         function check_price_str($price)
         {
             return Url::cdouble(trim($price));
         }
         $price_ar = array_unique(array_map('check_price_str', explode(",", $price_str)));
         $price_str = '';
         if ($price_ar) {
             asort($price_ar);
             foreach ($price_ar as $price) {
                 if ($price > 0) {
                     $price_str .= ($price_str != '' ? ',' : '') . $price;
                 }
             }
         }
     }
     $this->checkFormInput('Tên Danh mục', 'name', $name, 'str', true, '', 1, 255);
     $this->checkFormInput('Tên vắn tắt', 'brief_name', $brief_name, 'str', false, '', 1, 255);
     //$this->checkFormInput('Từ khoá','keywords',$keywords,'str',false,'',0,20);
     $this->checkFormInput('Mô tả', 'description', $description, 'str', false, '', 0, 250);
     if (Url::get('cmd') == 'edit' && $this->cat['parent_id'] == 0 && $parent_id && DB::select("category", 'parent_id=' . $this->cat['id'])) {
         $this->setFormError("parent_id", 'Không thể chuyển "Danh mục có danh mục con" thành một "Danh mục con" của "Danh mục khác" được!');
     }
     if (!$this->errNum) {
         $new_row = array('name' => $name, 'brief_name' => $brief_name ? $brief_name : $name, 'keywords' => AZLib::word_limit($keywords, 20, ''), 'description' => $description, 'parent_id' => $parent_id, 'ref_id' => $ref_id, 'status' => $status, 'tag_search' => $tag_search, 'img_server' => IMAGE_SERVER_NO, 'price_str' => $price_str, 'recomend' => $recomend);
         if (Url::get('cmd') == 'edit') {
             if ($position > 0 && $position != $this->cat['position']) {
                 $max_pos = (int) DB::fetch("SELECT max(position) AS max_pos FROM category WHERE parent_id=" . $parent_id, 'max_pos');
                 if ($position > $max_pos) {
                     $position = $max_pos + 1;
                 }
                 $new_row['position'] = $position;
             } else {
                 $position = $this->cat['position'];
             }
             $id = $this->cat['id'];
             DB::update('category', $new_row, 'id=' . $this->cat['id']);
             /*if($this->cat['parent_id']==0 && $parent_id){
             			DB::update('category', array('parent_id'=>0),'parent_id='.$this->cat['parent_id']);
             		}*/
         } else {
             $max_pos = (int) DB::fetch("SELECT max(position) AS max_pos FROM category WHERE parent_id=" . $parent_id, 'max_pos');
             if ($position > $max_pos || $position == 0) {
                 $position = $max_pos + 1;
             }
             $new_row['position'] = $position;
             $id = DB::insert('category', $new_row);
         }
         if ($_FILES['cat_image']['tmp_name']) {
             if (Url::get('cmd') == 'edit') {
                 AZLib::ftp_image_delete_file('category/' . $this->cat['id'] . '.gif', $this->cat['img_server']);
             }
             /*if(AZLib::ftp_image_connect(IMAGE_SERVER_NO)){
             			if(!AZLib::ftp_check_dir('category/',true,IMAGE_SERVER_NO)){
             				break ;
             			}
             				
             			$file_name	='category/'.$id.'.gif';
             			$sourceName =$_FILES['cat_image']['tmp_name'];
             			AZLib::ftp_image_put_file($file_name,$sourceName,IMAGE_SERVER_NO);
             			//@fopen('http://'.IMAGE_PATH.'?del_cat=1',"r");
             		}*/
             if (AZLib::ftp_check_dir('category/', true, IMAGE_SERVER_NO)) {
                 $file_name = 'category/' . $id . '.gif';
                 $sourceName = $_FILES['cat_image']['tmp_name'];
                 AZLib::ftp_image_put_file($file_name, $sourceName, IMAGE_SERVER_NO);
                 //@fopen('http://'.IMAGE_PATH.'?del_cat=1',"r");
             }
         }
         if ($id && DB::select('category', 'position="' . $position . '" AND id!="' . $id . '" AND parent_id="' . $parent_id . '"')) {
             DB::query('UPDATE category SET position=position+1 WHERE position>=' . $position . ' AND position<=' . $this->cat['position'] . ' AND parent_id="' . $parent_id . '" AND id!=' . $id);
         }
         $all_zones = $this->zones;
         $sql_inset = "";
         if ($zoneids) {
             foreach ($zoneids as $zoneid) {
                 if (isset($all_zones[$zoneid])) {
                     unset($all_zones[$zoneid]);
                 } else {
                     $sql_inset .= ($sql_inset != '' ? ',' : '') . "({$zoneid},{$id})";
                 }
             }
         }
         if ($sql_inset) {
             $sql_inset = "INSERT INTO category_zone_cat (zoneid, catid) VALUES " . $sql_inset;
             DB::query($sql_inset);
         }
         if ($all_zones) {
             $zoneids = implode(",", array_keys($all_zones));
             if ($zoneids) {
                 DB::query("DELETE FROM category_zone_cat WHERE catid={$id} AND zoneid IN({$zoneids})");
             }
         }
         //AZLib::del_cache_zone_cat();
         AZLib::getCats(1, true);
         if (Url::get('cmd') == 'edit' && $this->cat['parent_id'] != $parent_id) {
             //đổi danh mục cha => cập nhật lại tin
             $catid = $this->cat['id'];
             $level_1 = 0;
             $level_2 = 0;
             if ($parent_id) {
                 if (CGlobal::$allCategories[$parent_id]['parent_id']) {
                     $level_1 = CGlobal::$allCategories[$parent_id]['parent_id'];
                     $level_2 = $parent_id;
                 } else {
                     $level_1 = $parent_id;
                     $level_2 = $catid;
                 }
             } else {
                 $level_1 = $catid;
                 $level_2 = 0;
             }
             DB::update("item", array("level_1_catid" => $level_1, "level_2_catid" => $level_2), "category_id={$catid}");
             if (MEMCACHE_ON) {
                 AZMemcache::clear();
             }
         }
         if ($this->cat) {
             Url::redirect_current();
         } else {
             Url::redirect_current(array('cmd'));
         }
     }
 }
Exemplo n.º 2
0
<?php

require_once '../includes/auth.php';
//Auth...
require_once '../core/Debug.php';
//System Debug...
require_once '../core/config.php';
//System Config...
require_once '../core/Init.php';
//System Init...
$act = Url::get('act');
$id = Url::get('id');
switch ($act) {
    case 'remove':
        if ($id) {
            AZMemcache::do_remove($id);
            echo "Đã xóa xong {$id}";
            exit;
        }
        break;
    case 'clear':
        if (AZMemcache::clear()) {
            echo "done";
            exit;
        }
        break;
    default:
        echo ":D hehe";
        exit;
        break;
}