| 
 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.
 
 | 1. / 2. / ... 
 <?php
 // ClanSphere 2009 - www.clansphere.net
 // $Id: edit.php 3009 2009-05-03 14:57:11Z hajo $
 
 $cs_lang = cs_translate('shop');
 
 $files_gl = cs_files();
 require_once('mods/categories/functions.php');
 $data = array();
 
 $img_max['width'] = 250;
 $img_max['height'] = 250;
 $img_max['size'] = 912000;
 $img_filetypes = array('gif','jpg','png');
 
 if(empty($_GET['id']) AND empty($_POST['submit'])) {
 
 $data['item']['action'] = $cs_lang['edit'];
 $data['item']['link'] = cs_url('shop','manage');
 echo cs_subtemplate(__FILE__,$data,'shop','no_selection');
 
 } else {
 
 if (!empty($_POST['submit'])) {
 $error = '';
 
 if(empty($_POST['item_name'])) {
 $error .= cs_html_br(1) . '- ' . $cs_lang['no_name'];
 }
 
 if(empty($_POST['categories_id'])) {
 $error .= cs_html_br(1) . '- ' . $cs_lang['no_game'];
 }
 
 $img_size = empty($files_gl['picture']['tmp_name']) ? 0 : getimagesize($files_gl['picture']['tmp_name']);
 
 if(!empty($files_gl['picture']['tmp_name']) AND empty($img_size) OR $img_size[2] > 3) {
 $error .= cs_html_br(1) . '- ' . $cs_lang['ext_error'];
 } elseif(!empty($files_gl['picture']['tmp_name'])) {
 switch($img_size[2]) {
 case 1:
 $extension = 'gif'; break;
 case 2:
 $extension = 'jpg'; break;
 case 3:
 $extension = 'png'; break;
 }
 
 if($img_size[0] > $img_max['width']) {
 $error .= cs_html_br(1) . '- ' . $cs_lang['too_wide'];
 }
 
 if($img_size[1] > $img_max['height']) {
 $error .= cs_html_br(1) . '- ' . $cs_lang['too_high'];
 }
 
 if($files_gl['picture']['size'] > $img_max['size']) {
 $error .= cs_html_br(1) . '- ' . $cs_lang['too_big'];
 }
 }
 }
 
 if (empty($_POST['submit']) || !empty($error)) {
 
 $item_id = empty($_POST['submit']) ? (int) $_GET['id'] : $_POST['item_id'];
 $data['item'] = cs_sql_select(__FILE__,'item','*','item_id = \''.$item_id.'\'');
 $data['item']['item_id'] = empty($error) ? (int) $_GET['id'] : (int) $_POST['item_id'];
 $data['item']['message'] = empty($error) ? $cs_lang['fill_in'] : $cs_lang['error_occured'] . $error;
 $data['item']['item_name'] = empty($_POST['item_name']) ? $data['item']['item_name'] : $_POST['item_name'];
 
 $data['item']['public'] = ($data['item']['item_public'] == 1) ? 'checked="checked"' : '';
 
 $cat = empty($_POST['categories_id']) ? $data['item']['categories_id'] : $_POST['categories_id'];
 $data['categories']['dropdown'] = cs_categories_dropdown('shop',$cat);
 
 $data['item']['action'] = cs_url('shop','edit');
 
 $data['item']['picture'] = empty($data['item']['item_picture']) ? '-' : cs_html_img('uploads/shop/' . $data['item']['item_picture']);
 $matches[1] = $cs_lang['pic_infos'];
 $return_types = '';
 foreach($img_filetypes AS $add) {
 $return_types .= empty($return_types) ? $add : ', ' . $add;
 }
 $matches[2] = $cs_lang['max_width'] . $img_max['width'] . ' px' . cs_html_br(1);
 $matches[2] .= $cs_lang['max_height'] . $img_max['height'] . ' px' . cs_html_br(1);
 $matches[2] .= $cs_lang['max_size'] . cs_filesize($img_max['size']) . cs_html_br(1);
 $matches[2] .= $cs_lang['filetypes'] . $return_types;
 
 $data['item']['matches'] = cs_abcode_clip($matches);
 $data['if']['picture_remove'] = !empty($data['item']['item_picture']) ? TRUE : FALSE;
 
 echo cs_subtemplate(__FILE__,$data,'shop','edit');
 
 } else {
 
 $cs_item['item_name'] = $_POST['item_name'];
 $cs_item['categories_id'] = (!empty($_POST['categories_id'])) ? (int)$_POST['categories_id'] : cs_categories_create('shop', $_POST['categories_name']);
 $cs_item['item_public'] = (empty($_POST['item_public'])) ? '0' : '1';
 $cs_item['item_url'] = $_POST['item_url'];
 
 
 $item_id = (int) $_POST['item_id'];
 
 if(empty($_POST['pic_del']) AND empty($files_gl['picture']['tmp_name'])) {
 
 $cells = array_keys($cs_item);
 $values = array_values($cs_item);
 cs_sql_update(__FILE__,'item',$cells,$values,$item_id);
 
 } elseif(isset($_POST['pic_del']) AND empty($files_gl['picture']['tmp_name'])) {
 
 $select = cs_sql_select(__FILE__,'shop','item_picture','item_id = \''.$item_id.'\'');
 
 cs_unlink('shop', $select['item_picture']);
 
 $cs_item['item_picture'] = '';
 
 $cells = array_keys($cs_item);
 $values = array_values($cs_item);
 cs_sql_update(__FILE__,'item',$cells,$values,$item_id);
 
 } else {
 
 $select = cs_sql_select(__FILE__,'item','item_picture','item_id = \''.$item_id.'\'');
 $url = 'uploads/item/' . $select['item_picture'];
 cs_unlink('shop', $select['item_picture']);
 $filename = 'picture-' . $item_id . '.' . $extension;
 cs_upload('shop',$filename,$files_gl['picture']['tmp_name']);
 
 $cs_item['item_picture'] = $filename;
 
 $cells = array_keys($cs_item);
 $values = array_values($cs_item);
 cs_sql_update(__FILE__,'item',$cells,$values,$item_id);
 }
 
 cs_redirect($cs_lang['changes_done'], 'shop','manage') ;
 }
 }
 
 |