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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
| <?php
function parts(){
global $db;
$db->connect();
//echo "------".$_POST['changed']."------";
//echo "=======".$_POST['art_id']."======";
//if (!$_POST['changed']) echo 'its changed is false now';
//$query="SELECT id,brandname FROM cms_shop_brand ORDER BY brandname";
if (!$_POST['rc']){
$query="SELECT min(cat_id) from cms_shop_cat";// echo $query;
$db->query($query);
$db->next_record();
$rc=$db->f(0);
}
else{
$rc=$_POST['rc'];
}
//$brandid=get_param('brandid');
//echo "-----".$_POST['brandid']."-----";
if (!$_POST['brandid']){
//$query= "SELECT id FROM cms_shop_brand WHERE rc_brand=".tosql($rc)." LIMIT 1";//echo $query;
//$db->query($query);
//$db->next_record();
//$brandid=$db->f(0);
$brandid=0;
}
else{
$brandid=$_POST['brandid'];
}
$query= "SELECT id,brandname FROM cms_shop_brand WHERE rc_brand=".tosql($rc)." ORDER BY brandname";
if ($brandid>0){
$brandlistraw=get_options($query,false,true,$brandid);
$brandlist="<option value='-1'>Toutes les marques</option>";
$brandlist.=$brandlistraw;
}
else{
$brandlist.="<option value='-1' SELECTED>Toutes les marques</option>";
$brandlist.=get_options($query,false,true,-1);
}
if (!$_POST['changed']){
//echo "<br>SOOOOOO<br>";
//echo "changed state-----".$_POST['changed']."------<br>";
//echo "changed item=======".$_SESSION['artid']."======";
if (($_POST['do_add'])&&($_SESSION['newitem'])){
if ($_FILES['picfile']['name']) $pictname=handle_file('picfile'); else $pictname="nopic.gif";
if ($_FILES['picfile1']['name']) $pictname1=handle_file('picfile1'); else $pictname1="spacer.gif";
if ($_FILES['picfile2']['name']) $pictname2=handle_file('picfile2'); else $pictname2="spacer.gif";
if ($_FILES['picfile3']['name']) $pictname3=handle_file('picfile3'); else $pictname3="spacer.gif";
if (!$_POST['prix'])
$prix='0.00';
else
$prix=$_POST['prix'];
$query="INSERT INTO cms_shop_items (rc_id,brand_id,item_description,item_trax,item_id,item_price,item_pic,item_pic1,item_pic2,item_pic3,item_comment,item_nosell,item_new,item_special,item_ftech) VALUES (";
$query.=tosql($rc).",".tosql($brandid).",".tosql($_POST['descr']).",".tosql($_POST['itemtrax']).",".tosql($_POST['itemid']).",";
$query.=tosql($prix).",".tosql($pictname).",".tosql($pictname1).",".tosql($pictname2).",".tosql($pictname3).",".tosql($_POST['comment']).",".get_checkbox_value($_POST['nosell'],'1','0').",".get_checkbox_value($_POST['newitem'],'1','0').",".get_checkbox_value($_POST['itemspecial'],'1','0').",";
$query.=tosql($_POST['ftech']).")";
$db->query($query);
unset($_SESSION['newitem']);
}//end adding
//---------------------
//refleter les modifs
elseif (($_POST['do_update'])&&($_SESSION['artid'])){
//echo "<br>GOING TO UPDATE<br>";
if ($_FILES['picfile']['name']) $pictname=handle_file('picfile'); else $pictname="nopic.gif";
if ($_FILES['picfile1']['name']) $pictname1=handle_file('picfile1'); else $pictname1="spacer.gif";
if ($_FILES['picfile2']['name']) $pictname2=handle_file('picfile2'); else $pictname2="spacer.gif";
if ($_FILES['picfile3']['name']) $pictname3=handle_file('picfile3'); else $pictname3="spacer.gif";
$query='UPDATE cms_shop_items SET ';
$query.='rc_id='.tosql($rc);
$query.=',brand_id='.tosql($brandid);
//$query.=',target_id='.tosql($_POST['targetid']);
$query.=',item_description='.tosql($_POST['descr']);
$query.=',item_trax='.tosql($_POST['itemtrax']);
$query.=',item_id='.tosql($_POST['itemid']);
$query.=',item_dia='.tosql($_POST['itemdia']);
$query.=',item_price='.tosql($_POST['prix']);
if ($_FILES['picfile']['name']) $query.=',item_pic='.tosql($pictname);
if ($_FILES['picfile1']['name']) $query.=',item_pic1='.tosql($pictname1);
if ($_FILES['picfile2']['name']) $query.=',item_pic2='.tosql($pictname2);
if ($_FILES['picfile3']['name']) $query.=',item_pic3='.tosql($pictname3);
$query.=',item_comment='.tosql($_POST['comment']);
$query.=',item_nosell='.get_checkbox_value($_POST['nosell'],'1','0');
$query.=',item_special='.get_checkbox_value($_POST['itemspecial'],'1','0');
$query.=',item_new='.get_checkbox_value($_POST['newitem'],'1','0');
$query.=',item_ftech='.tosql($_POST['ftech']);
$query.=' WHERE id='.tosql($_SESSION['artid']);
$db->query($query); //echo $query;
unset($_SESSION['artid']);
}
elseif ($_POST['do_delpic']){
$query="UPDATE cms_shop_items SET item_pic='nopic.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['do_delpic1']){
$query="UPDATE cms_shop_items SET item_pic1='spacer.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['do_delpic2']){
$query="UPDATE cms_shop_items SET item_pic2='spacer.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['do_delpic3']){
$query="UPDATE cms_shop_items SET item_pic3='spacer.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
//end refleter les modifs
//---------------------
if (($_POST['cd_item']||$_POST['del_item']) && $_POST['selectedrow']) {
$_SESSION['artid']=$_POST['selectedrow'];
}
elseif (!$_POST['do_delpic'] && !$_POST['do_delpic1'] && !$_POST['do_delpic2'] && !$_POST['do_delpic3']&& !$_POST['changed'])
{
unset($_SESSION['artid']);
}
//end changement d'article
}
//--------------------
//get the list of categories
$query="SELECT b.cat_id,concat(a.category,' > ',b.category) FROM cms_shop_cat a, cms_shop_cat b WHERE (b.lang=1 AND b.parentid=a.cat_id) ORDER BY (a.cat_id+b.parentid*b.parentid)";
$query1="SELECT cat_id, category FROM cms_shop_cat WHERE parentid=0";
if (isset($rc)){
$catlist_raw=get_options($query,false,true,$rc);
$catlist_raw.=get_options($query1,false,true,$rc);
$catlist.=$catlist_raw;
}
else{
$catlist_raw=get_options($query,false,true,0);
$catlist_raw.=get_options($query1,false,true,0);
$catlist.=$catlist_raw;
}
if (($_POST['add_item'])||($_POST['do_delpic'])||($_POST['do_delpic1'])||($_POST['do_delpic2'])||($_POST['do_delpic3'])||($_POST['changed']=='1')){
if ($_POST['selectedrow']) $_SESSION['artid']=$_POST['selectedrow'];
include('newart.php');
}
elseif ($_POST['cd_item'])
include('newart.php');
elseif ($_POST['del_item']){
$query= "DELETE FROM cms_shop_items WHERE id=".tosql($_POST['selectedrow']);
$db->query($query);
include('articles.frm.php');
}
else
include('articles.frm.php');
}
function brands(){
global $db;
$db->connect();
if ($_POST['do_add']){
$query="INSERT INTO cms_shop_brand (brandname,rc_brand) values(".tosql($_POST['brandname']).",".tosql($_POST['categorieid']).")";
$db->query($query);
}
elseif ($_POST['do_update']){
$query="UPDATE cms_shop_brand SET brandname=".tosql($_POST['brandname']).",rc_brand=".tosql($_POST['categorieid'])." WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
if (($_POST['cd_item']||$_POST['del_item']) && $_POST['selectedrow']) {
$_SESSION['artid']= $_POST['selectedrow'];
}
elseif (!$_POST['do_delpic'])
unset($_SESSION['artid']);
if ($_POST['add_item'])
include('newbrand.php');
elseif ($_POST['cd_item'])
include('newbrand.php');
elseif ($_POST['del_item']){
$query= "DELETE FROM cms_shop_brand WHERE id=".tosql($_POST['selectedrow']);
$db->query($query);
include('brands.frm.php');
}
else
include('brands.frm.php');
}
function models(){
global $db;
$db->connect();
$query="SELECT id,brandname FROM cms_shop_brand ORDER BY brandname";
$brandlist=get_options($query,false,true,$_POST['brandid']);
if (($_POST['do_add1'])&&($_SESSION['artid'])){
if ($_FILES['picwhite']['name']) $pictname=handle_file('picwhite','modeles/'); else $pictname="spacer.gif";
if ($_FILES['picblack']['name']) $pictname1=handle_file('picblack','modeles/'); else $pictname1="spacer.gif";
if ($_FILES['picgrey']['name']) $pictname2=handle_file('picgrey','modeles/'); else $pictname2="spacer.gif";
if ($_FILES['picred']['name']) $pictname3=handle_file('picred','modeles/'); else $pictname3="spacer.gif";
$query="INSERT INTO cms_shop_model(brand_id,descr,trax,year) values(".tosql($_POST['brandid']).",".tosql($_POST['descr']).",".tosql($_POST['trax']).",".tosql($_POST['year']).")";
$db->query($query);
unset($_SESSION['artid']);
}
elseif (($_POST['do_update'])&&($_SESSION['artid'])){
if ($_FILES['picwhite']['name']) $pictname=handle_file('picwhite','modeles/'); else $pictname="spacer.gif";
if ($_FILES['picblack']['name']) $pictname1=handle_file('picblack','modeles/'); else $pictname1="spacer.gif";
if ($_FILES['picgrey']['name']) $pictname2=handle_file('picgrey','modeles/'); else $pictname2="spacer.gif";
if ($_FILES['picred']['name']) $pictname3=handle_file('picred','modeles/'); else $pictname3="spacer.gif";
$query="UPDATE cms_shop_model SET brand_id=".tosql($_POST['brandid']).",descr=".tosql($_POST['descr']).",trax=".tosql($_POST['trax']).",year=".tosql($_POST['year']);
if ($_FILES['picwhite']['name']) $query.=',pic_white='.tosql($pictname);
if ($_FILES['picblack']['name']) $query.=',pic_black='.tosql($pictname1);
if ($_FILES['picgrey']['name']) $query.=',pic_grey='.tosql($pictname2);
if ($_FILES['picred']['name']) $query.=',pic_red='.tosql($pictname3);
$query.=',x1='.tosql($_POST['x1']).',y1='.tosql($_POST['y1']).',x2='.tosql($_POST['x2']).',y2='.tosql($_POST['y2']);
$query.=" WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
unset($_SESSION['newitem']);
}
elseif ($_POST['do_delwhite']){
$query="UPDATE cms_shop_model SET pic_white='nomodel.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['do_delblack']){
$query="UPDATE cms_shop_model SET pic_black='nomodel.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['do_delgrey']){
$query="UPDATE cms_shop_model SET pic_grey='nomodel.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['do_delred']){
$query="UPDATE cms_shop_model SET pic_red='nomodel.gif' WHERE id=".tosql($_SESSION['artid']);
$db->query($query);
}
elseif ($_POST['del_item']){
$query= "DELETE FROM cms_shop_model WHERE id=".tosql($_POST['selectedrow']);
$db->query($query);
}
if (($_POST['cd_item']||$_POST['del_item']) && $_POST['selectedrow']) {
$_SESSION['artid']= $_POST['selectedrow'];
}
elseif (!$_POST['do_delwhite'] && !$_POST['do_delblack'] && !$_POST['do_delgrey'] && !$_POST['do_delred']&& !$_POST['changed'])
{
unset($_SESSION['artid']);
}
if ($_POST['add_item'])
include('newmodel.php');
elseif ($_POST['cd_item'])
include('newmodel.php');
elseif ($_POST['del_item']){
$query= "DELETE FROM cms_shop_model WHERE id=".tosql($_POST['selectedrow']);
$db->query($query);
include('models.frm.php');
}
else
include('models.frm.php');
}
function handle_file($itemname='picfile',$path='articles/'){//returns the document_id, used in inserts and updates
global $db;
$ext=strtolower(substr($_FILES[$itemname]['name'],strlen($_FILES[$itemname]['name'])-3,3));
$http=substr($_FILES[$itemname]['name'],0,4);
if ( ($ext=='jpg')||($ext=='gif')||($ext=='png') )//&&($http!='http')
{
$srcf=stripslashes($_FILES[$itemname]['name']);
$_SESSION['pic_name']=$srcf;
$_SESSION['pic_size']=$_FILES['pic_file']['size'];
$_SESSION['pic_type']=$ext;
$tmp_path='../../images/'.$path;
$destf= $tmp_path.$srcf;
if (copy($_FILES[$itemname]['tmp_name'],$destf))
{
if (($ext=='jpg')||($ext=='gif')||($ext=='png'))
save_thumb($srcf,$ext,$tmp_path);
return $srcf;
}
else
{
return false;
}
}
else
{//make hyperlink
$_SESSION['pic_name']=$_FILES[$itemname]['name'];
$_SESSION['pic_size']=0;
$_SESSION['pic_type']=$ext;
return true;
}
}
?> |
Partager