Jeff PHP framework
0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
|
00001 <?php 00021 class menuAdminTable extends adminTable { 00022 00030 function __construct($table, $opts=null) { 00031 00032 parent::__construct($table, $opts); 00033 00034 } 00035 00043 public function view() { 00044 00045 $order = cleanInput('get', 'order', 'string'); 00046 00047 $tot_fk = count($this->_fkeys); 00048 $tot_sf = count($this->_sfields); 00049 00050 // get order field and direction 00051 preg_match("#^([^ ,]*)\s?((ASC)|(DESC))?.*$#", $order, $matches); 00052 $field_order = isset($matches[1]) ? $matches[1] : null; 00053 $order_dir = isset($matches[2]) ? $matches[2] : null; 00054 00055 $fields_names = $this->_registry->db->getFieldsName($this->_table); 00056 00057 $pag = new pagination($this->_efp, $this->_registry->db->getNumRecords($this->_table, null, $this->_primary_key)); 00058 00059 $limit = array($pag->start(), $this->_efp); 00060 00061 if(count($this->_changelist_fields)) { 00062 if(!in_array($this->_primary_key, $this->_changelist_fields)) 00063 array_unshift($this->_changelist_fields, $this->_primary_key); 00064 $field_selection = isset($this->_fkeys[$field_order]) 00065 ? 'a.'.implode(', a.', $this->_changelist_fields) 00066 : implode(',', $this->_changelist_fields); 00067 } 00068 else 00069 $field_selection = isset($this->_fkeys[$field_order]) ? "a.*" : "*"; 00070 00071 // different queries if the order field is a foreign key 00072 if(isset($this->_fkeys[$field_order])) { 00073 $records = $this->_registry->db->autoSelect($field_selection, array($this->_table." AS a", $this->_fkeys[$field_order]['table']." AS b"), "a.$field_order=b.".$this->_fkeys[$field_order]['key'], "b.".$this->_fkeys[$field_order]['order']." $order_dir", $limit); 00074 } 00075 else 00076 $records = $this->_registry->db->autoSelect($field_selection, $this->_table, null, $order, $limit); 00077 00078 $all = "<span class=\"link\" onclick=\"$$('#atbl_form input[type=checkbox]').setProperty('checked', 'checked');\">".__("all")."</span>"; 00079 $none = "<span class=\"link\" onclick=\"$$('#atbl_form input[type=checkbox]').removeProperty('checked');\">".__("none")."</span>"; 00080 $heads = ($this->_edit_deny != 'all' || $this->_export) ? array("0"=>"$all | $none") : array(); 00081 foreach($fields_names as $fn) { 00082 if(!$this->_changelist_fields || in_array($fn, $this->_changelist_fields)) { 00083 $ord = $order == $fn." ASC" ? $fn." DESC" : $fn." ASC"; 00084 00085 if($order == $fn." ASC") { 00086 $jsover = "$(this).getNext('img').setProperty('src', '$this->_arrow_down_path')"; 00087 $jsout = "$(this).getNext('img').setProperty('src', '$this->_arrow_up_path')"; 00088 $a_style = "visibility:visible"; 00089 $apath = $this->_arrow_up_path; 00090 } 00091 elseif($order == $fn." DESC") { 00092 $jsover = "$(this).getNext('img').setProperty('src', '$this->_arrow_up_path')"; 00093 $jsout = "$(this).getNext('img').setProperty('src', '$this->_arrow_down_path')"; 00094 $js = "$(this).getNext('img').getNext('img').setStyle('visibility', 'visible')"; 00095 $a_style = "visibility:visible"; 00096 $apath = $this->_arrow_down_path; 00097 } 00098 else { 00099 $js = ''; 00100 $jsover = "$(this).getNext('img').setStyle('visibility', 'visible')"; 00101 $jsout = "$(this).getNext('img').setStyle('visibility', 'hidden')"; 00102 $a_style = "visibility:hidden"; 00103 $apath = $this->_arrow_up_path; 00104 } 00105 00106 $link = preg_replace("#/p/\d+/#", "/", $_SERVER['REQUEST_URI']); 00107 $link = preg_replace("#\?.*#", "", $link); 00108 $head_t = anchor($link."?order=$ord", __($fn), array('over'=>$jsover, 'out'=>$jsout)); 00109 $heads[] = $head_t." <img src=\"$apath\" alt=\"down\" style=\"$a_style\" />"; 00110 } 00111 } 00112 $heads[] = array("text"=>"", "class"=>"noBkg noBorder"); 00113 00114 $rows = array(); 00115 foreach($records as $r) { 00116 $input = "<input type=\"checkbox\" name=\"f[]\" value=\"".$r[$this->_primary_key]."\" />"; 00117 if($tot_fk) $r = $this->parseForeignKeys($r); 00118 if($tot_sf) $r = $this->parseSpecialFields($r); 00119 $r = $this->parseDateFields($r); 00120 if($this->_edit_deny=='all' && !$this->_export) $row = $r; 00121 elseif(is_array($this->_edit_deny) && in_array($r[$this->_primary_key], $this->_edit_deny)) $row = array_merge(array(""), $r); 00122 else $row = array_merge(array($input), $r); 00123 00124 $link = anchor("?insert&parent=".$r[$this->_primary_key], __("addSubvoice")); 00125 $rows[] = array_merge($row, array(array('text' => $link, 'class' => 'noBkg noBorder'))); 00126 } 00127 00128 00129 $this->_view->setTpl('table'); 00130 $this->_view->assign('class', 'generic wide'); 00131 $this->_view->assign('caption', __("RecordInTable")." ".$this->_table); 00132 $this->_view->assign('heads', $heads); 00133 $this->_view->assign('rows', $rows); 00134 00135 $table = $this->_view->render(); 00136 00137 if($this->_edit_deny!='all' || $this->_export) { 00138 $myform = new form('post', 'atbl_form', array("validation"=>false)); 00139 $formstart = $myform->sform('?edit'.($order ? "&order=$order" : ""), null); 00140 $formend = $myform->cform(); 00141 } 00142 else { 00143 $formstart = ''; 00144 $formend = ''; 00145 } 00146 00147 if($this->_edit_deny=='all') { 00148 $input_edit = ''; 00149 $input_delete = ''; 00150 } 00151 else { 00152 $onclick = "var checked = false; 00153 var felements = $$('#atbl_form input[type=checkbox]'); 00154 for(var i=0;i<felements.length;i++) if(felements[i].checked) {checked = true;break;} 00155 if(!checked) {alert('".jsVar(__("SelectAtleastRecord"))."'); return false;}"; 00156 $input_edit = $myform->input('submit_edit', 'submit', __("edit"), array("js"=>"onclick=\"$onclick\"")); 00157 if($this->_deletion) 00158 $input_delete = $myform->input('submit_delete', 'submit', __("delete"), array("js"=>"onclick=\"$onclick return confirmSubmit('".jsVar(__("ProcedeDeleteSelectedRecords"))."')\"")); 00159 else $input_delete = ''; 00160 } 00161 00162 if($this->_export) { 00163 $onclick = "var checked = false; 00164 var felements = $$('#atbl_form input[type=checkbox]'); 00165 for(var i=0;i<felements.length;i++) if(felements[i].checked) {checked = true;break;} 00166 if(!checked) {alert('".jsVar(__("SelectAtleastRecord"))."'); return false;}"; 00167 $input_export_selected = $myform->input('submit_export_selected', 'submit', __("exportSelected"), array("js"=>"onclick=\"$onclick \"")); 00168 $input_export_all = $myform->input('submit_export_all', 'submit', __("exportAll"), array()); 00169 $input_where_query = $myform->hidden('where_query', ''); 00170 00171 } 00172 else { 00173 $input_export_selected = null; 00174 $input_export_all = null; 00175 $input_where_query = ''; 00176 } 00177 00178 $link_insert = $this->_insertion ? anchor("?insert", __("insertNewRecord")) : null; 00179 00180 $this->_view->setTpl('admin_table'); 00181 $this->_view->assign('table', $table); 00182 $this->_view->assign('link_insert', $link_insert); 00183 $this->_view->assign('formstart', $formstart); 00184 $this->_view->assign('formend', $formend); 00185 $this->_view->assign('input_edit', $input_edit); 00186 $this->_view->assign('input_delete', $input_delete); 00187 $this->_view->assign('input_where_query', $input_where_query); 00188 $this->_view->assign('input_export_selected', $input_export_selected); 00189 $this->_view->assign('input_export_all', $input_export_all); 00190 $this->_view->assign('psummary', $pag->summary()); 00191 $this->_view->assign('pnavigation', $pag->navigation()); 00192 00193 return $this->_view->render(); 00194 } 00195 00212 protected function formElement($myform, $fname, $field, $id, $opts=null) { 00213 00214 $id_f = preg_replace("#\s#", "_", $id); // replace spaces with '_' in form names as POST do itself 00215 00216 $required = $field['null']=='NO' ? true : false; 00217 00218 $records = $this->_registry->db->autoSelect("*", $this->_table, $this->_primary_key."='$id'", null); 00219 $value = count($records) ? $records[0][$fname] : null; 00220 00221 $parent = is_null($value) ? cleanInput('get', 'parent', 'int') : $value; 00222 00223 if($fname=='url') { 00224 return $myform->cinput($fname."_".$id_f, 'text', $myform->retvar($fname, $value), array("url", sprintf(__('startingFromSiteRoot'), ROOT)), array("required"=>$required, "size"=>$field['max_length']<40 ? $field['max_length'] : 40, "maxlength"=>$field['max_length'])); 00225 00226 } 00227 elseif($fname=='parent') { 00228 return $myform->hidden($fname."_".$id_f, $parent); 00229 00230 } 00231 elseif($fname=='groups') { 00232 $sf = $this->_sfields[$fname]; 00233 $options = $this->_registry->db->autoSelect(array($sf['key']." AS value", $sf['field']." AS label"), $sf['table'], $sf['where'], $sf['order']); 00234 return $myform->cmulticheckbox($fname."_".$id_f."[]", $myform->retvar($fname."_".$id_f, explode(",", $value)), $options, array(htmlVar(__($fname)), __('menuGroupsAdminExp')), array("required"=>$required)); 00235 00236 } 00237 else { 00238 return parent::formElement($myform, $fname, $field, $id, $opts); 00239 } 00240 00241 00242 00243 } 00244 } 00245 00246 ?>