![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: custom_field_addedit.php 141 2008-04-05 16:41:20Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/system/custom_field_addedit.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 /* 7 * Custom Field Add/Edit 8 * 9 */ 10 11 // check permissions 12 $perms = &$AppUI->acl(); 13 if (!$perms->checkModule('system', 'edit')) { 14 $AppUI->redirect('m=public&a=access_denied'); 15 } 16 17 require_once ($AppUI->getSystemClass('CustomFields')); 18 19 $titleBlock = new CTitleBlock('Custom Fields - Add/Edit', 'customfields.png', 'admin', 'admin.custom_field_addedit'); 20 $titleBlock->addCrumb('?m=system', 'system admin'); 21 $titleBlock->addCrumb('?m=system&a=custom_field_editor', 'custom fields'); 22 $titleBlock->show(); 23 24 $field_id = w2PgetParam($_POST, 'field_id', null) != null ? w2PgetParam($_POST, 'field_id', null) : w2PgetParam($_GET, 'field_id', 0); 25 $delete_field = w2PgetParam($_GET, 'delete', 0); 26 $module = w2PgetParam($_GET, 'module', null) == null ? w2PgetParam($_POST, 'module', null) : w2PgetParam($_GET, 'module', null); 27 28 $select_newitem = w2PgetParam($_POST, 'select_newitem', null); 29 $select_items = w2PgetParam($_POST, 'select_items', array()); 30 31 $select_delitem = w2PgetParam($_POST, 'delete_item', null); 32 33 $yesno = w2PgetSysVal('GlobalYesNo'); 34 if ($select_newitem != null) { 35 $select_items[] = $select_newitem; 36 } 37 38 if ($select_delitem != null) { 39 $new_selectitems = array(); 40 41 foreach ($select_items as $itm) { 42 if ($itm != $select_delitem) 43 $new_selectitems[] = $itm; 44 } 45 46 unset($select_items); 47 $select_items = &$new_selectitems; 48 } 49 50 // Loading the page for the first time 51 if (w2PgetParam($_GET, 'field_id', null) != null) { 52 $custom_fields = new CustomFields($module, 'addedit', null, 'edit'); 53 54 if ($delete_field) { 55 $custom_fields->deleteField($field_id); 56 $AppUI->redirect(); 57 } 58 59 $cf = &$custom_fields->fieldWithId($field_id); 60 61 if (is_object($cf)) { 62 $field_name = $cf->fieldName(); 63 $field_description = $cf->fieldDescription(); 64 $field_htmltype = $cf->fieldHtmlType(); 65 $field_extratags = $cf->fieldExtraTags(); 66 $field_order = $cf->fieldOrder(); 67 $field_published = $cf->fieldPublished(); 68 69 if ($field_htmltype == 'select') { 70 $select_options = new CustomOptionList($field_id); 71 $select_options->load(); 72 $select_items = $select_options->getOptions(); 73 } 74 } else { 75 //No such field exists with this ID 76 $AppUI->setMsg('Couldnt load the Custom Field, It might have been deleted somehow.'); 77 $AppUI->redirect(); 78 } 79 80 $edit_title = $AppUI->_('Edit Custom Field In'); 81 } else { 82 $edit_title = $AppUI->_('New Custom Field In'); 83 84 $field_name = w2PgetParam($_POST, 'field_name', null); 85 $field_description = w2PgetParam($_POST, 'field_description', null); 86 $field_htmltype = w2PgetParam($_POST, 'field_htmltype', 'textinput'); 87 $field_extratags = w2PgetParam($_POST, 'field_extratags', null); 88 $field_order = w2PgetParam($_POST, 'field_order', null); 89 $field_published = w2PGetParam($_POST, 'field_published', 0); 90 } 91 92 $html_types = array('textinput' => $AppUI->_('Text Input'), 'textarea' => $AppUI->_('Text Area'), 'checkbox' => $AppUI->_('Checkbox'), 'select' => $AppUI->_('Select List'), 'label' => $AppUI->_('Label'), 'separator' => $AppUI->_('Separator'), 'href' => $AppUI->_('Weblink'), ); 93 94 $visible_state = array(); 95 96 foreach ($html_types as $k => $ht) { 97 if ($k == $field_htmltype) { 98 $visible_state['div_' . $k] = 'display : block'; 99 } else { 100 $visible_state['div_' . $k] = 'display : none'; 101 } 102 } 103 ?> 104 <script> 105 function hideAll() { 106 var selobj = document.getElementById('htmltype'); 107 for (i = 0, i_cmp = selobj.options.length; i < i_cmp; i++) { 108 var atbl = document.getElementById('atbl_'+selobj.options[i].value); 109 var adiv = document.getElementById('div_'+selobj.options[i].value); 110 111 atbl.style.visibility = 'hidden'; 112 adiv.style.display = 'none'; 113 } 114 } 115 116 function showAttribs() { 117 hideAll(); 118 119 var selobj = document.getElementById('htmltype'); 120 var seltype = selobj.options[selobj.selectedIndex].value; 121 122 var atbl = document.getElementById('atbl_'+seltype); 123 var adiv = document.getElementById('div_'+seltype); 124 atbl.style.visibility = 'visible'; 125 adiv.style.display = 'block'; 126 } 127 128 function addSelectItem() { 129 frm = document.getElementById('custform'); 130 frm.action = '?m=system&a=custom_field_addedit'; 131 frm.submit(); 132 } 133 134 function deleteItem( itmname ) { 135 del = document.getElementById('delete_item'); 136 del.value = itmname; 137 addSelectItem(); 138 } 139 140 function postCustomField() { 141 frm = document.getElementById('custform'); 142 frm.action = '?m=system&a=custom_field_editor'; 143 sql = document.getElementById('dosql'); 144 sql.name = 'dosql'; 145 frm.submit(); 146 } 147 </script> 148 <form method="POST" action="?m=system&a=custom_field_editor" id="custform"> 149 <table class="std" width="100%"> 150 <th colspan="2"> 151 <?php echo $edit_title ?> <?php echo $AppUI->_($module) ?> <?php echo $AppUI->_('Module') ?> 152 <input type="hidden" name="field_id" value="<?php echo $field_id; ?>" /> 153 <input type="hidden" name="module" value="<?php echo $module ?>" /> 154 <input type="hidden" name="dontdosql" id="dosql" value="do_custom_field_aed" /> 155 </td></tr> 156 <tr><td> 157 <?php echo $AppUI->_('Field Name/Identifier') ?>: 158 159 <?php echo $AppUI->_('(No Spaces)') ?> 160 </td><td> 161 <input type="text" class="text" name="field_name" maxlength="100" value="<?php echo $field_name ?>" onblur='this.value=this.value.replace(/[^a-z|^A-Z|^0-9]*/gi,"");' /> 162 </td></tr> 163 <tr><td> 164 <?php echo $AppUI->_('Field Description') ?>: 165 </td><td> 166 <input type="text" class="text" name="field_description" size="40" maxlength="250" value="<?php echo $field_description ?>" /> 167 </td></tr> 168 <tr><td> 169 <?php echo $AppUI->_('Field Display Type') ?>: 170 </td><td> 171 <?php echo arraySelect($html_types, 'field_htmltype', 'id="htmltype" class="text" onChange="javascript:showAttribs()"', $field_htmltype); ?> 172 </td></tr> 173 <?php if (count($yesno)) { ?> 174 <tr><td> 175 <?php echo $AppUI->_('Field Published') ?>: 176 </td><td> 177 <?php echo arraySelect($yesno, 'field_published', 'id="fieldpublished" class="text"', $field_published); ?> 178 </td></tr> 179 <?php } ?> 180 <tr><td> 181 <?php echo $AppUI->_('Field Display Order') ?>: 182 </td><td> 183 <input style="text-align:right" type="text" class="text" size="4" name="field_order" maxlength="3" value="<?php echo $field_order ?>" /> 184 </td></tr> 185 <tr><td colspan="2"> 186 <hr /> 187 <tr><td> 188 <?php echo $AppUI->_('HTML Tag Options') ?>: 189 </td> 190 <td> 191 <input type="text" class="text" size="80" name="field_extratags" value="<?php echo $field_extratags ?>" /> 192 </td></tr> 193 </td></tr> 194 <tr><td colspan="2"> 195 <div id="div_select" style="<?php echo $visible_state['div_select'] ?>"> 196 <table id="atbl_select"> 197 <tr><td colspan="2"> 198 <b><?php echo $AppUI->_('List of Options') ?>:</b> 199 </td></tr> 200 <tr><td colspan="2"> 201 <input type="hidden" name="delete_item" value="0" id="delete_item" /> 202 <table> 203 <?php 204 $s = ''; 205 foreach ($select_items as $itm) { 206 $s .= '<tr><td>'; 207 $s .= '<li>' . $itm . '</li>'; 208 $s .= '<input type="hidden" name="select_items[]" value="' . $itm . '" />'; 209 $s .= '</td><td>'; 210 $s .= '<a href="javascript:deleteItem(\'' . $itm . '\')">[Delete]</a>'; 211 $s .= '</td></tr>'; 212 } 213 echo $s; 214 ?> 215 <tr><td> 216 <li><input type="text" name="select_newitem" /></td><td><input type="button" value="<?php echo $AppUI->_('Add') ?>" onclick="javascript:addSelectItem()" /></li> 217 </td></tr> 218 </table> 219 </td></tr> 220 </table> 221 <hr /> 222 </div> 223 <div id="div_textinput" style="<?php echo $visible_state['div_textinput'] ?>"> 224 <table id="atbl_textinput"> 225 </table> 226 </div> 227 <div id="div_textarea" style="<?php echo $visible_state['div_textarea'] ?>"> 228 <table id="atbl_textarea"> 229 </table> 230 </div> 231 <div id="div_checkbox" style="<?php echo $visible_state['div_checkbox'] ?>"> 232 <table id="atbl_checkbox"> 233 </table> 234 </div> 235 <div id="div_label" style="<?php echo $visible_state['div_label'] ?>"> 236 <table id="atbl_label"> 237 </table> 238 </div> 239 <div id="div_separator" style="<?php echo $visible_state['div_separator'] ?>"> 240 <table id="atbl_separator"> 241 </table> 242 </div> 243 </td></tr> 244 <tr><td colspan="2" align="right"> 245 <input type="button" value="Cancel" onclick="location = '?m=system&a=custom_field_editor';" /> 246 <input type="button" value="Save" onclick="javascript:postCustomField()" /> 247 </td></tr> 248 </form> 249 </table>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jan 8 03:00:03 2009 | Cross-referenced by PHPXref 0.7 |