function array_menu($parent_id = 0, $group_id = 2, $close = array()) { $ci =& get_instance(); if ($group_id == 'all') { $query = "SELECT \n\t\t\t\t\t\t\tsys_menu.*,sys_resources.name AS permission \n\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\tsys_menu \n\t\t\t\t\t\tLEFT JOIN sys_resources ON(sys_menu.resources_id=sys_resources.id) \n\t\t\t\t\t \tWHERE sys_menu.parent_id = {$parent_id} \n\t\t\t\t\t\tORDER BY sys_menu.id ASC"; } else { $query = "SELECT \n\t\t\t\t\t\t\tsys_menu.*,sys_resources.name AS permission \n\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\tsys_menu \n\t\t\t\t\t\tLEFT JOIN sys_resources ON(sys_menu.resources_id=sys_resources.id) \n\t\t\t\t\t \tWHERE sys_menu.parent_id = {$parent_id} AND sys_menu.group_id = {$group_id} \n\t\t\t\t\t\tORDER BY sys_menu.id ASC"; } $result = $ci->db->query($query); $data = array(); if ($result->num_rows() > 0) { foreach ((array) $result->result_array() as $row) { $allow_menu = check_user($row['permission'], false); if ($allow_menu) { $r['id'] = $row['id']; $r['parent_id'] = $row['parent_id']; $r['text'] = strtoupper($row['name']); $r['url'] = $row['url']; $r['state'] = $close && in_array($row['id'], $close) ? 'closed' : ''; $r['children'] = array_menu($row['id'], $group_id, $close); $data[] = $r; } } } return $data; }
/** * @Function formEnum * @Author Jonah * @Created 3/20/08 6:02 PM * $info is from the get table info function. * opts: * raw - no table wrapper * choose - show the "choose..." option from the pulldown, off by default * get_array - no output, just return array of enum choices */ function formEnum(&$info, $opts = false) { global $R; if (is_array($opts)) { extract($opts); } if (!$this->{$info}[field] && $default) { $this->{$info}[field] = $default; } // figure out the array $select = str_replace("'", "", $info[size]); // turn string into an array $select = explode(",", $select); if ($get_array) { return $select; } if (!$raw) { ?> <tr> <td align="right" valign="top" class="fieldlabel" > <p><label><nobr><?php echo camelcaps($info[field]); ?> :</nobr></label></p> </td><td><?php } // Now do the menu itself. if ($choose) { // The following seems very retarded. Probably a better way. JB 3/25/08 11:20 AM // $select = array_merge(array(""=>"Choose..."),$select); // $select = array_unshift($select,"Choose..."); if ($choose === true) { $choose = "Choose..."; } $selectchoose = array("" => $choose) + $select; unset($select); foreach ($selectchoose as $choose) { if (contains("choose", strtolower($choose))) { $select[''] = $choose; } else { $select[$choose] = $choose; } } } $fname = $this->getFname($info[field]); if ($this->debug || $R[debug]) { da("Default is :" . $this->{$info}[field] . " for field {$info['field']} with id {$this->id}."); } array_menu($select, $fname, $this->{$info}[field]); if (!$raw) { ?> </td></tr><?php } }