Blame view

libs/sale.class.php 3.56 KB
42868d70   andryeyev   Создал GIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  <?php
  class Sale{
   var $db = null;
   var $tpl = null;
   var $error = null;
  //var $id = false;
  
   function Sale(&$db,&$tpl,&$error){
    $this->db = &$db;
    $this->tpl = &$tpl;
    $this->error = &$error;
   }
   
  
  
   function viewAllNews($lang='ru'){
    $search = array();
    $sql = "select *,url".($lang=='ukr'?'_ukr':'')." as url from sale where 1=1";
    if(count($search))$sql .= "AND " . implode(" AND ",$search)." ";
    $sql .= " order by sort asc";
    $pagerOptions = Array(
      'mode' => 'Sliding',
      'delta' => 6,
      'perPage' => 60,
      'spacesBeforeSeparator' => 1,
      'spacesAfterSeparator' => 1
    );
  
    $this->tpl->assign('saleAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
   }
  
  
   function viewOneNews($id,&$row){
    $sql = "select * from sale where id=? limit 1";
    $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
    $this->tpl->assign('news',$row);
   }
   
  
   function admin_infoEditNewsOne($id){
    $sql = "select * from sale where id=? limit 1";
    $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
    $this->tpl->assign('news',$row);
   }
  
  
   function trim(&$data){
    foreach($data as $key=>$value){
     if(!is_array($data[$key]))$data[$key] = trim($value);
    }
   }
  
   function valid($data,$upload = null){
    if(isset($data['rss_rubric'])){
     if( !preg_match("/^([0-9]+)$/",$data['rss_rubric']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ðóáðèêà.";
    }
    
    if(isset($data['title'])){
     if( !preg_match("/.{1,150}/i",$data['title']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå, îò 1-150 ñèìâîëîâ.";
    }
  
    if(isset($data['text'])){
     if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Îïèñàíèå.";
    }
  
    if(isset($upload['pic']['name']) && $upload['pic']['name']!=null){
     $type = substr(strrchr($upload['pic']['name'],"."),1);
     if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
    }
  
   return ( count($this->error) ) ? true : false;
   }
  
  
   function SaveNews($data,$upload = null){
    $table_name = "sale";
    if($data['update_id']>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$id = $data['update_id'];$where = "id=$id";}else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$id = $this->db->nextId('mySequencesale');$where = null;}
  
    $fields_values = array("id"=>$id,"url"=>$data['url'],"url_ukr"=>$data['url_ukr']);
   // if(!$data['update_id']){$fields_values['mktime'] = mktime();}
    if(isset($data['delete_pic']) && $data['delete_pic']==1){
     $this->deletePic($id);
     $fields_values['pic'] = null;
    }
    if($upload['pic']['tmp_name']){
     $this->deletePic($id);
     $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"755",'height'=>"755",'upload_path'=>"./uploaded/pic/news/"));
    }
  
    $this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
    return $id;
   }
  
   function deletePic($id){
    $sql = "select pic from sale where id=?";
    $news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
    @unlink("./uploaded/pic/news/{$news['pic']}");
   }
   
   function admin_deleteNewsOne($id){
    $this->deletePic($id);
    $sql = "delete from sale where id=?";
    $this->db->query($sql,array($id));
   }
   
   
   function SaveSort($data){
  	$table_name = "sale";
  	foreach($data['id'] as $key=>$id){
  		$fields_values = array('sort'=>$data['sort'][$key]);
  		$this->db->autoExecute($table_name, $fields_values, DB_AUTOQUERY_UPDATE,"id=$id");
  	}
   }
  
  
   function displayNewsSave(){
    $this->tpl->assign("tpl","sale_save.tpl");
   }
   
   function displayNews(){
    $this->tpl->assign("tpl","sale.tpl");
   }
  
   function displayNewsOne(){
    $this->tpl->assign("tpl","sale_one.tpl");
   }
  
  }
  ?>