| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | include '../../../include/cp_header.php'; |
|---|
| 4 | include '../../../class/xoopsformloader.php'; |
|---|
| 5 | include 'function.php'; |
|---|
| 6 | |
|---|
| 7 | $GLOBALS['xoopsOption']['template_main'] = 'extgallery_admin_public_category.html'; |
|---|
| 8 | |
|---|
| 9 | if(isset($_GET['op'])) { |
|---|
| 10 | $op = $_GET['op']; |
|---|
| 11 | } else { |
|---|
| 12 | $op = 'default'; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | if(isset($_POST['step'])) { |
|---|
| 16 | $step = $_POST['step']; |
|---|
| 17 | } else { |
|---|
| 18 | $step = 'default'; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | switch($op) { |
|---|
| 22 | |
|---|
| 23 | case 'create': |
|---|
| 24 | |
|---|
| 25 | switch($step) { |
|---|
| 26 | |
|---|
| 27 | case 'enreg': |
|---|
| 28 | |
|---|
| 29 | $catHandler = xoops_getmodulehandler('publiccat', 'extgallery'); |
|---|
| 30 | $data = array( |
|---|
| 31 | 'cat_pid'=>$_POST['cat_pid'], |
|---|
| 32 | 'cat_name'=>$_POST['cat_name'], |
|---|
| 33 | 'cat_desc'=>$_POST['cat_desc'], |
|---|
| 34 | 'cat_weight'=>$_POST['cat_weight'], |
|---|
| 35 | 'cat_date'=>time(), |
|---|
| 36 | 'cat_imgurl'=>$_POST['cat_imgurl'] |
|---|
| 37 | ); |
|---|
| 38 | $catHandler->createCat($data); |
|---|
| 39 | |
|---|
| 40 | redirect_header("public-category.php", 3, _AM_EXTGALLERY_CAT_CREATED); |
|---|
| 41 | |
|---|
| 42 | break; |
|---|
| 43 | |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | break; |
|---|
| 47 | |
|---|
| 48 | case 'modify': |
|---|
| 49 | |
|---|
| 50 | switch($step) { |
|---|
| 51 | |
|---|
| 52 | case 'enreg': |
|---|
| 53 | |
|---|
| 54 | if(isset($_POST['submit'])) { |
|---|
| 55 | $catHandler = xoops_getmodulehandler('publiccat', 'extgallery'); |
|---|
| 56 | $catHandler->modifyCat($_POST); |
|---|
| 57 | |
|---|
| 58 | redirect_header("public-category.php", 3, _AM_EXTGALLERY_CAT_MODIFIED); |
|---|
| 59 | } elseif($_POST['delete']) { |
|---|
| 60 | xoops_cp_header(); |
|---|
| 61 | extgalleryAdminMenu(2); |
|---|
| 62 | xoops_confirm(array("cat_id"=>$_POST['cat_id'],"step"=>'enreg'), 'public-category.php?op=delete', _AM_EXTGALLERY_DELETE_CAT_CONFIRM); |
|---|
| 63 | xoops_cp_footer(); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | break; |
|---|
| 67 | |
|---|
| 68 | case 'default': |
|---|
| 69 | default: |
|---|
| 70 | |
|---|
| 71 | // Check if they are selected category |
|---|
| 72 | if(!isset($_POST['cat_id'])) { |
|---|
| 73 | redirect_header("photo.php",3,_AM_EXTGALLERY_NO_CATEGORY_SELECTED); |
|---|
| 74 | exit; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | $catHandler = xoops_getmodulehandler('publiccat', 'extgallery'); |
|---|
| 78 | $photoHandler = xoops_getmodulehandler('publicphoto', 'extgallery'); |
|---|
| 79 | |
|---|
| 80 | $cat = $catHandler->getCat($_POST['cat_id']); |
|---|
| 81 | $photosCat = $photoHandler->getCatPhoto($cat); |
|---|
| 82 | |
|---|
| 83 | xoops_cp_header(); |
|---|
| 84 | extgalleryAdminMenu(2); |
|---|
| 85 | |
|---|
| 86 | $selectedPhoto = '../images/blank.gif'; |
|---|
| 87 | $photoArray = array(); |
|---|
| 88 | foreach($photosCat as $photo) { |
|---|
| 89 | if($photo->getVar('photo_serveur') != "") { |
|---|
| 90 | $url = $photo->getVar('photo_serveur')."thumb_".$photo->getVar('photo_name'); |
|---|
| 91 | } else { |
|---|
| 92 | $url = XOOPS_URL."/uploads/extgallery/public-photo/thumb/thumb_".$photo->getVar('photo_name'); |
|---|
| 93 | } |
|---|
| 94 | if($photo->getVar('photo_id') == $cat->getVar('photo_id')) { |
|---|
| 95 | $selectedPhoto = $url; |
|---|
| 96 | } |
|---|
| 97 | $photoArray[$photo->getVar('photo_id')] = $url; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | echo "<script type='text/JavaScript'>"; |
|---|
| 101 | echo "function ChangeThumb() { |
|---|
| 102 | |
|---|
| 103 | var formSelect; |
|---|
| 104 | var thumb = new Array();"; |
|---|
| 105 | |
|---|
| 106 | echo "thumb[0] = '../images/blank.gif';\n"; |
|---|
| 107 | foreach($photoArray as $k => $v) { |
|---|
| 108 | echo "thumb[".$k."] = '".$v."';\n"; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | echo "formSelect = document.getElementById('photo_id'); |
|---|
| 112 | |
|---|
| 113 | document.getElementById('thumb').src = thumb[formSelect.options[formSelect.selectedIndex].value]; |
|---|
| 114 | }"; |
|---|
| 115 | echo "</script>"; |
|---|
| 116 | |
|---|
| 117 | echo '<fieldset><legend style="font-weight:bold; color:#990000;">'._AM_EXTGALLERY_MOD_PUBLIC_CAT.'</legend>'; |
|---|
| 118 | |
|---|
| 119 | $photoSelect = "\n".'<select size="1" name="photo_id" id="photo_id" onChange="ChangeThumb();" onkeydown="ChangeThumb();">'."\n"; |
|---|
| 120 | $photoSelect .= '<option value="0"> </option>'."\n"; |
|---|
| 121 | foreach($photosCat as $photo) { |
|---|
| 122 | if($photo->getVar("photo_id") == $cat->getVar('photo_id')) { |
|---|
| 123 | $photoSelect .= '<option value="'.$photo->getVar("photo_id").'" selected="selected">'.$photo->getVar("photo_desc").' ('.$photo->getVar("photo_name").')</option>'."\n"; |
|---|
| 124 | } else { |
|---|
| 125 | $photoSelect .= '<option value="'.$photo->getVar("photo_id").'">'.$photo->getVar("photo_desc").' ('.$photo->getVar("photo_name").')</option>'."\n"; |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | $photoSelect .= '</select>'."\n"; |
|---|
| 129 | |
|---|
| 130 | $form = new XoopsThemeForm(_AM_EXTGALLERY_MOD_PUBLIC_CAT, 'create_cat', 'public-category.php?op=modify', 'post', true); |
|---|
| 131 | $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_PARENT_CAT, $catHandler->getSelect('cat_pid', 'leaf', true, $cat->getVar('cat_pid')))); |
|---|
| 132 | $form->addElement(new XoopsFormText(_AM_EXTGALLERY_NAME, 'cat_name', '70', '255', $cat->getVar('cat_name','e')),false); |
|---|
| 133 | $form->addElement(new XoopsFormText(_AM_EXTGALLERY_WEIGHT, 'cat_weight', '4', '4', $cat->getVar('cat_weight')),false); |
|---|
| 134 | $form->addElement(new XoopsFormDhtmlTextArea(_AM_EXTGALLERY_DESC, 'cat_desc', $cat->getVar('cat_desc','e')), false); |
|---|
| 135 | $elementTrayThumb = new XoopsFormElementTray(_AM_EXTGALLERY_THUMB); |
|---|
| 136 | $elementTrayThumb->addElement(new XoopsFormLabel("", $photoSelect."<img style=\"float:left; margin-top:5px;\" id=\"thumb\" src=\"$selectedPhoto\" />")); |
|---|
| 137 | $form->addElement(new XoopsFormText(_AM_EXTGALLERY_CAT_IMG, 'cat_imgurl', '70', '150', $cat->getVar('cat_imgurl','e')),false); |
|---|
| 138 | $form->addElement($elementTrayThumb); |
|---|
| 139 | $elementTrayButton = new XoopsFormElementTray(""); |
|---|
| 140 | $elementTrayButton->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit")); |
|---|
| 141 | $elementTrayButton->addElement(new XoopsFormButton("", "delete", _DELETE, "submit")); |
|---|
| 142 | $form->addElement($elementTrayButton); |
|---|
| 143 | $form->addElement(new XoopsFormHidden("cat_id", $_POST['cat_id'])); |
|---|
| 144 | $form->addElement(new XoopsFormHidden("step", 'enreg')); |
|---|
| 145 | $form->display(); |
|---|
| 146 | |
|---|
| 147 | echo '</fieldset>'; |
|---|
| 148 | |
|---|
| 149 | xoops_cp_footer(); |
|---|
| 150 | |
|---|
| 151 | break; |
|---|
| 152 | |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | break; |
|---|
| 156 | |
|---|
| 157 | case 'delete': |
|---|
| 158 | |
|---|
| 159 | switch($step) { |
|---|
| 160 | |
|---|
| 161 | case 'enreg': |
|---|
| 162 | |
|---|
| 163 | $catHandler = xoops_getmodulehandler('publiccat', 'extgallery'); |
|---|
| 164 | |
|---|
| 165 | $catHandler->deleteCat($_POST['cat_id']); |
|---|
| 166 | |
|---|
| 167 | redirect_header("public-category.php", 3, _AM_EXTGALLERY_CAT_DELETED); |
|---|
| 168 | |
|---|
| 169 | break; |
|---|
| 170 | |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | break; |
|---|
| 174 | |
|---|
| 175 | case 'default': |
|---|
| 176 | default: |
|---|
| 177 | |
|---|
| 178 | $catHandler = xoops_getmodulehandler('publiccat', 'extgallery'); |
|---|
| 179 | |
|---|
| 180 | xoops_cp_header(); |
|---|
| 181 | extgalleryAdminMenu(2); |
|---|
| 182 | |
|---|
| 183 | echo '<fieldset><legend style="font-weight:bold; color:#990000;">'._AM_EXTGALLERY_MODDELETE_PUBLICCAT.'</legend>'; |
|---|
| 184 | |
|---|
| 185 | echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">'._AM_EXTGALLERY_INFORMATION.'</legend>'."\n"; |
|---|
| 186 | echo _AM_EXTGALLERY_MODDELETE_PUBLICCAT_INFO."\n"; |
|---|
| 187 | echo '</fieldset><br />'."\n"; |
|---|
| 188 | |
|---|
| 189 | $form = new XoopsThemeForm(_AM_EXTGALLERY_MODDELETE_PUBLICCAT, 'modify_cat', 'public-category.php?op=modify', 'post', true); |
|---|
| 190 | $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_CATEGORY, $catHandler->getSelect('cat_id', false, false, 0, "", true))); |
|---|
| 191 | $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit")); |
|---|
| 192 | $form->display(); |
|---|
| 193 | |
|---|
| 194 | echo '</fieldset>'; |
|---|
| 195 | echo '<br />'; |
|---|
| 196 | echo '<fieldset><legend style="font-weight:bold; color:#990000;">'._AM_EXTGALLERY_ADD_PUBLIC_CAT.'</legend>'; |
|---|
| 197 | |
|---|
| 198 | echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">'._AM_EXTGALLERY_INFORMATION.'</legend>'."\n"; |
|---|
| 199 | echo _AM_EXTGALLERY_ADD_PUBLIC_CAT_INFO."\n"; |
|---|
| 200 | echo '</fieldset><br />'."\n"; |
|---|
| 201 | |
|---|
| 202 | $form = new XoopsThemeForm(_AM_EXTGALLERY_ADD_PUBLIC_CAT, 'create_cat', 'public-category.php?op=create', 'post', true); |
|---|
| 203 | $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_PARENT_CAT, $catHandler->getSelect('cat_pid', 'leaf', true))); |
|---|
| 204 | $form->addElement(new XoopsFormText(_AM_EXTGALLERY_NAME, 'cat_name', '70', '255'),true); |
|---|
| 205 | $form->addElement(new XoopsFormText(_AM_EXTGALLERY_WEIGHT, 'cat_weight', '4', '4'),false); |
|---|
| 206 | $form->addElement(new XoopsFormDhtmlTextArea(_AM_EXTGALLERY_DESC, 'cat_desc', ''), false); |
|---|
| 207 | $form->addElement(new XoopsFormText(_AM_EXTGALLERY_CAT_IMG, 'cat_imgurl', '70', '150'), false); |
|---|
| 208 | $form->addElement(new XoopsFormHidden("step", 'enreg')); |
|---|
| 209 | $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit")); |
|---|
| 210 | $form->display(); |
|---|
| 211 | |
|---|
| 212 | echo '</fieldset>'; |
|---|
| 213 | |
|---|
| 214 | xoops_cp_footer(); |
|---|
| 215 | |
|---|
| 216 | break; |
|---|
| 217 | |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | ?> |
|---|