phpBMS

root/trunk/phpbms/choicelist.php

Revision 746, 6.8 kB (checked in by brieb, 7 months ago)
  • choicelist deletes and adds were returning errors
  • Property svn:keywords set to LastChangedBy LastChangedDate LastChangedRevision
Line 
1<?php
2/*
3 $Rev$ | $LastChangedBy$
4 $LastChangedDate$
5 +-------------------------------------------------------------------------+
6 | Copyright (c) 2004 - 2010, Kreotek LLC                                  |
7 | All rights reserved.                                                    |
8 +-------------------------------------------------------------------------+
9 |                                                                         |
10 | Redistribution and use in source and binary forms, with or without      |
11 | modification, are permitted provided that the following conditions are  |
12 | met:                                                                    |
13 |                                                                         |
14 | - Redistributions of source code must retain the above copyright        |
15 |   notice, this list of conditions and the following disclaimer.         |
16 |                                                                         |
17 | - Redistributions in binary form must reproduce the above copyright     |
18 |   notice, this list of conditions and the following disclaimer in the   |
19 |   documentation and/or other materials provided with the distribution.  |
20 |                                                                         |
21 | - Neither the name of Kreotek LLC nor the names of its contributore may |
22 |   be used to endorse or promote products derived from this software     |
23 |   without specific prior written permission.                            |
24 |                                                                         |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS     |
26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT       |
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
28 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
29 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   |
30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT        |
31 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   |
32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   |
33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT     |
34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   |
35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    |
36 |                                                                         |
37 +-------------------------------------------------------------------------+
38*/
39
40
41class choiceList{
42
43    var $db;
44
45    function choiceList($db){
46
47                $this->db = $db;
48
49    }//end function init
50
51
52    function deleteList($listname){
53
54        $deletestatement = "
55            DELETE FROM
56                `choices`
57            WHERE
58                `listname` = '".mysql_real_escape_string($listname)."' ";
59            $queryresult=$this->db->query($deletestatement);
60
61            echo "ok";
62    }//end function deleteList
63
64
65    function addToList($listname, $value){
66
67        $insertstatement = "
68            INSERT INTO
69                `choices`(
70                `listname`,
71                `thevalue`
72            ) VALUES (
73                '".mysql_real_escape_string($listname)."',
74                '".mysql_real_escape_string($value)."'
75            )";
76
77        $this->db->query($insertstatement);
78
79        echo "ok";
80
81    }//end function addToList
82
83
84    function displayList($queryresult, $blankvalue){
85
86        while($therecord = $this->db->fetchArray($queryresult)){
87
88            $display = $therecord["thevalue"];
89            $theclass = "";
90
91            if($therecord["thevalue"]==""){
92
93                $display = "&lt;".$blankvalue."&gt;";
94                $theclass = ' class="choiceListBlank" ';
95
96            }
97
98            ?><option value="<?php echo $therecord["thevalue"]?>" <?php echo $theclass?>><?php echo $display?></option><?php
99
100        }//end while
101
102    }//end function displayList
103
104
105    function displayBox($listname, $blankvalue, $listid){
106
107        $blankvalue = str_replace("<","",$blankvalue);
108        $blankvalue = str_replace(">","",$blankvalue);
109
110        $querystatement = "
111            SELECT
112                thevalue
113            FROM
114                choices
115            WHERE
116                listname='".mysql_real_escape_string($listname)."'
117            ORDER BY
118                thevalue";
119
120        $queryresult = $this->db->query($querystatement);
121
122        ?>
123        <p id="MLListP">
124                <select id="MLlist" name="MLList" size="12" onchange="updateML(this)">
125                        <?php $this->displayList($queryresult, $blankvalue)?>
126                </select>
127        </p>
128        <p id="MLAddDelP">
129                <input type="button" id="MLDelete" name="MLDelete" value="delete" class="Buttons" disabled onclick="delML()" /><br/>
130                <input type="button" id="MLInsert" name="MLInsert" value="insert" class="Buttons" onclick="insertML()"/>
131        </p>
132        <p id="MLAddTextP">
133                <input name="MLaddedit" id="MLaddedit" type="text"/>
134                <input name="MLblankvalue" id="MLblankvalue" type="hidden" value="<?php echo $blankvalue?>"/>
135        </p>
136        <p id="MLAddP">
137                <input type="button" id="MLaddeditbutton" name="MLaddeditbutton" value="add" class="Buttons" onclick="addeditML('<?php echo $blankvalue?>')" />
138        </p>
139        <p id="MLStatus" class="small">&nbsp;</p>
140        <div align="right">
141                <input type="button" id="MLok" name="MLok" value="ok" class="Buttons" style="width:75px;" onclick="clickOK('<?php echo APP_PATH?>','<?php echo $listid?>','<?php echo $listname?>')"/>
142                <input type="button" id="MLcancel" name="MLcancel" value="cancel" class="Buttons" style="width:75px;" onclick="closeBox('<?php echo $listid?>');"/>&nbsp;
143        </div>
144        <?php
145
146    }//end function
147
148}//end class
149
150
151
152
153
154if(!isset($noOutput)){
155
156    require_once("include/session.php");
157    $thelist = new choiceList($db);
158
159    if(!isset($_GET["cm"]))
160        $error = new appError(200, "passed parameters not set");
161
162    switch($_GET["cm"]){
163
164        case "shw":
165
166            if(!isset($_GET["ln"]))
167                    $_GET["ln"]="shippingmethod";
168
169            if(!isset($_GET["bv"]))
170                $_GET["bv"]="none";
171
172            if(!isset($_GET["lid"]))
173                $_GET["lid"]=NULL;
174
175            $thelist->displayBox($_GET["ln"],$_GET["bv"],$_GET["lid"]);
176            break;
177
178        case "del":
179
180            if(!isset($_GET["ln"]))
181                $error = new appError(200, "passed parameters not set");
182
183            $thelist->deleteList($_GET["ln"]);
184            break;
185
186        case "add":
187
188            if(!isset($_GET["ln"]) || !isset($_GET["val"]))
189                $error = new appError(200, "passed parameters not set");
190
191            $thelist->addToList($_GET["ln"], $_GET["val"]);
192            break;
193
194    }//endswitch
195
196}//endif
197
198
199?>
Note: See TracBrowser for help on using the browser.
Copyright © 2010 Kreotek, LLC. All Rights reserved.