*
* Usage example:
*
* $orderby=get_order();
* $query="SELECT * FROM fic_courses $orderby";
* $courses=db_get($query,MYSQL_ASSOC);
* $headers=array(
* 'course_id'=>'',
* 'title'=>'Course Title',
* 'date_start_course'=>'Start',
* 'date_end_course'=>'End',
* 'date_start_reg'=>'Reg Starts',
* 'date_end_reg'=>'Reg Ends',
* 'active'=>'Active?',
* 'entry_date'=>'Created'
* );
* show_list($courses,$headers);
*
*
* Accompanying CSS for table output:
*
* .list
* {
* border:1px solid #999;
* }
* .list th
* {
* background:#eee;
* border:1px solid #000;
* font-weight:bold;
* }
* .list th a
* {
* display:block;
* padding:0 14px;
* }
* .list th a:hover
* {
* background-color:#fff;
* }
* .row1
* {
* background:#ddd;
* }
* .row2
* {
* background:#ccc;
* }
* .row1:hover, .row2:hover
* {
* background-color:#fec;
* }
* .current-sort
* {
* background:#fda;
* }
* .sort-desc
* {
* background:#fec url(../img/up.gif) no-repeat right;
* }
* .sort-asc
* {
* background:#fec url(../img/down.gif) no-repeat right;
* }
*
* Accompanying JavaScript for select all / inverse:
*
*
*
*/
/**
* Show a list of values, for forms.
* @param array $list associative array
* @param array $headers column name => column title (for table heads)
* @param string $type checkbox, radio, simple
* @param array $array actions to display in actions select list
* @param string $form_id id of form holding list
* @param bool $sortable whether or not to show sortable column headers (links in th's)
* @param array|string $selected if type is checkbox, array otherwise string with one val
*/
function show_list($list,$headers,$type='checkbox',$actions=null,$form_id=null,$sortable=true,$selected=null)
{
if ( is_array($list) && count($list)>0 && is_array($headers) )
{
if ( $type!='simple' && !empty($_GET['sort']) && !empty($_GET['order']) )
{
form_hidden('sort',$_GET['sort']);
form_hidden('order',$_GET['order']);
}
echo "\n".'
'; } if ($type=='radio'||$type='checkbox-small') { echo '
'; form_submit('submit','submit','button1',$actions[0].' »'); echo '
'; } else { echo ''; echo ''; form_select('action','action','text2',$actions,''); form_submit('submit','submit','button1','Go »'); echo '
'; } } } elseif ( !is_array($headers) ) { echo "\n".'No records found.
'; } } /** * Show table headers. * @param array $headers column name => column title (for table heads) * @param string $type type of list that is being shown * @param bool $sortable whether or not to show sortable column headers (links in th's) */ function show_headers($headers,$type,$sortable=true) { echo "\n".'
* list_edit_ids('course_id','../forms/course.php','SELECT * FROM fic_courses','1');
*
* @param string $name name of id field
* @param string $form path to form to be used to items
* @param string $q_front front half of query
* @param string $q_where where statement
* @param array $dates array of date field names, so they can be fixed for forms
* @param array $datetimes array of datetime field names, so they can be fixed for forms
*/
function list_edit_ids($name,$form,$q_front,$q_where='1',$dates=null,$datetimes=null)
{
if ( !empty($_SESSION[$name]) && is_array($_SESSION[$name]) )
{
$ids=implode(',',$_SESSION[$name]);
$orderby=get_orderby('session');
$query=$q_front.' WHERE '.$q_where." AND $name IN($ids) ".$orderby;
$records=db_get($query);
form_start($name);
foreach ($records as $record)
{
echo "\n".'You must select a record. Go back.
'; } } /** * Process a submitted list_edit_ids form. * @param array $name array of primary ids posted from the form, these are vital to the WHERE clause of the UPDATE statements. * @param string $table name of table being affected */ function list_update_ids($name,$table) { $keys=array_keys($_POST[$name]); foreach ($keys as $index) { foreach ($_POST as $key=>$val) { if ($key!='submit') { $posts[$index][$key]=$val[$index]; } } } foreach ($posts as $dataset) { $query=db_makeupdate($dataset,$table," WHERE $name='".$dataset[$name]."' "); db_query($query); } } ?>