source: extensions/MyPiwiShop/admin/options.php

Last change on this file was 27781, checked in by Miklfe, 10 years ago
File size: 3.8 KB
Line 
1<?php
2defined('MPS_PATH') or die('Hacking attempt!');
3
4// define type option
5  $select_type_opt=array(
6  'select'   =>'select',
7  'radio'    =>'radio',
8  'text'     =>'text',
9  'textarea' =>'textarea',
10  'checkbox' =>'checkbox',
11  );
12 
13// delete option
14  if(isset($_POST['check'])) {
15 
16   foreach($_POST['check'] AS $delete_id){
17   
18   pwg_query('
19   DELETE FROM '.MPS_OPTION_TABLE.'
20   WHERE `id` = '.$delete_id.';
21   ');
22   
23   pwg_query('
24   DELETE FROM '.MPS_PROD_OPT_TABLE.'
25   WHERE `opt_id` = '.$delete_id.';
26   ');
27 
28   pwg_query('
29   DELETE FROM '.MPS_OPT_VAL_TABLE.'
30   WHERE `select_id` = '.$delete_id.';
31   ');
32   
33   $page['infos']=l10n('deleted');
34   }
35   
36  }   
37
38// add/edit option
39  if (isset($_POST['option_add'])) {
40
41  //add option
42        if(empty($_POST['id'])) {
43         $order = array();
44         
45         $query ='SELECT *
46         FROM '.MPS_OPTION_TABLE.';';
47         $result = pwg_query($query);
48         
49         while($row = pwg_db_fetch_assoc($result)) {
50       $order[] = $row['order'];
51         }
52         
53         if (count($order) == 0) {
54          $order = 1;
55         } else {
56          $order = max($order)+1;
57         }
58       
59         $name          = $_POST['name'];
60     $type              = $_POST['type'];
61     $title             = $_POST['title'];
62         
63         if(isset($_POST['requi'])) {
64          $requi = $_POST['requi'];
65         } else {
66          $requi = 0;
67         }
68       
69         pwg_query('
70         INSERT into '.MPS_OPTION_TABLE.' (`name`,`type`,`titre`,`requi`,`order`)
71         VALUE (\''.$name.'\',\''.$type.'\',\''.$title.'\',\''.$requi.'\',\''.$order.'\')
72         ;');
73   
74         $select_id = pwg_db_insert_id();                       
75                       
76         if(isset($_POST['val'])) {
77         $val           = $_POST['val'];
78         
79      foreach($val as $val_ele) {
80           pwg_query('
81           INSERT into '.MPS_OPT_VAL_TABLE.' (`val` , `select_id`)
82           VALUE (\''.$val_ele.'\',\''.$select_id.'\')
83           ;');
84      }
85         
86         }
87         $page['infos']=l10n('Option registered');
88        }
89       
90  //edit option
91    if(!empty($_POST['id'])) {
92
93         $name  = $_POST['name'];
94     $type      = $_POST['type'];
95     $title     = $_POST['title'];
96         $id    = $_POST['id'];
97       
98         if(isset($_POST['requi'])) {
99           $requi = $_POST['requi'];
100          } else {
101           $requi = 0;
102          }
103
104         pwg_query('   
105         UPDATE '.MPS_OPTION_TABLE.'
106         SET `name` = \''.$name.'\', `type` = \''.$type.'\', `titre` = \''.$title.'\', `requi` = \''.$requi.'\'
107         WHERE `id` = '.$id.'
108         ;');
109       
110         pwg_query('
111         DELETE FROM '.MPS_OPT_VAL_TABLE.'
112         WHERE `select_id` =  '.$id.'
113         ;');
114   
115         if(isset($_POST['val'])){
116         $val           = $_POST['val'];
117         
118      foreach($val as $val_ele)
119      {
120           pwg_query('
121           INSERT into '.MPS_OPT_VAL_TABLE.' (`val` , `select_id`)
122           VALUE (\''.$val_ele.'\',\''.$id.'\')
123           ;');
124      }
125         
126         }
127         
128    $page['infos']=l10n('Option registered');
129        }
130  }
131
132// change option order
133  if(isset($_POST['newOrder'])) {
134 
135   $newOrder = explode(",", $_POST['newOrder']);
136   $ex           = array_pop($newOrder);
137   
138        foreach( $newOrder as $order => $id ) {
139       
140         $order = $order +1;
141     pwg_query('
142         UPDATE '.MPS_OPTION_TABLE.'
143         SET `order` = \''.$order.'\'
144         WHERE `id` = '.$id.'
145         ;');
146     } 
147         
148        $page['infos']=l10n('the order is changed');
149  }
150
151// set option
152  $query='
153  SELECT o.id, o.titre, o.name, o.type, o.requi, o.order, ov.val
154  FROM '.MPS_OPTION_TABLE.' AS o
155  LEFT JOIN '.MPS_OPT_VAL_TABLE.' AS ov ON ov.select_id = o.id
156  ORDER BY o.order
157  ;';
158 
159  $result = pwg_query($query);
160   while($row = pwg_db_fetch_assoc($result)) {
161   
162        if (!isset($option[ $row['id']])) {
163     $option[$row['id']] = array(
164          'id'    => $row['id'],
165          'title' => $row['titre'],
166          'name'  => $row['name'],
167          'type'  => $row['type'],
168          'requi' => $row['requi'],
169         );
170        }
171        $option[$row['id']]['val'][]=$row['val'];
172       
173   }
174 
175//template assign
176  $template->assign(array(
177         'mps_option'   => $option,
178         'mps_type_opt' => $select_type_opt
179         ));
180
181  $template->set_filename('mps_content', realpath(MPS_PATH . 'admin/template/options.tpl'));
182 
Note: See TracBrowser for help on using the repository browser.