/php/lib/list.php

Description

List functions for lists of values.

  • author:

    Mike Morgan <mike.morgan@oregonstate.edu>

    Usage example:

    1. $orderby=get_order();
    2. $query="SELECT * FROM fic_courses $orderby";
    3. $courses=db_get($query,MYSQL_ASSOC);
    4. $headers=array(
    5. 'course_id'=>'',
    6. 'title'=>'Course Title',
    7. 'date_start_course'=>'Start',
    8. 'date_end_course'=>'End',
    9. 'date_start_reg'=>'Reg Starts',
    10. 'date_end_reg'=>'Reg Ends',
    11. 'active'=>'Active?',
    12. 'entry_date'=>'Created'
    13. );
    14. show_list($courses,$headers);

    Accompanying CSS for table output:

    1. .list
    2. {
    3. border:1px solid #999;
    4. }
    5. .list th
    6. {
    7. background:#eee;
    8. border:1px solid #000;
    9. font-weight:bold;
    10. }
    11. .list th a
    12. {
    13. display:block;
    14. padding:0 14px;
    15. }
    16. .list th a:hover
    17. {
    18. background-color:#fff;
    19. }
    20. .row1
    21. {
    22. background:#ddd;
    23. }
    24. .row2
    25. {
    26. background:#ccc;
    27. }
    28. .row1:hover, .row2:hover
    29. {
    30. background-color:#fec;
    31. }
    32. .current-sort
    33. {
    34. background:#fda;
    35. }
    36. .sort-desc
    37. {
    38. background:#fec url(../img/up.gif) no-repeat right;
    39. }
    40. .sort-asc
    41. {
    42. background:#fec url(../img/down.gif) no-repeat right;
    43. }
    Accompanying JavaScript for select all / inverse:
    1. <script type="text/javascript">
    2. //<!--
    3. function selectAll(formObj,invert)
    4. {
    5. for (var i=0;i < formObj.elements.length;i++)
    6. {
    7. fldObj = formObj.elements[i];
    8. if (fldObj.type == 'checkbox')
    9. {
    10. if (invert==1)
    11. {
    12. fldObj.checked = (fldObj.checked) ? false : true;
    13. }
    14. else
    15. {
    16. fldObj.checked = true;
    17. }
    18. }
    19. }
    20. }
    21. //-->
    22. </script>

Functions
get_order (line 283)

Determine current sort order.

void get_order ()
get_orderby (line 293)

Determine whether or not list is currently sorted.

  • return: cleaned orderby clause based on saved sort information or null if no orderby is set in the defined method
mixed get_orderby ([string $method = 'get'])
  • string $method: which http method to check for sort information
list_edit_ids (line 334)

Parses $_POST for ids, shows edit forms for each id with populated data.

  • name will be used to retrieve an _array_ from $_POST of the same name
  • the form will be an include, with $posts[col_name] as the default for all values
  • try to keep your query simple (no crazy sorting, etc.) -- we're talking one record at a time here anyway
Example:
  1. list_edit_ids('course_id','../forms/course.php','SELECT * FROM fic_courses','1');

void list_edit_ids (string $name, string $form, string $q_front, [string $q_where = '1'], [array $dates = null], [array $datetimes = null])
  • string $name: name of id field
  • string $form: path to form to be used to items
  • string $q_front: front half of query
  • string $q_where: where statement
  • array $dates: array of date field names, so they can be fixed for forms
  • array $datetimes: array of datetime field names, so they can be fixed for forms
list_update_ids (line 370)

Process a submitted list_edit_ids form.

void list_update_ids (array $name, string $table)
  • array $name: array of primary ids posted from the form, these are vital to the WHERE clause of the UPDATE statements.
  • string $table: name of table being affected
show_headers (line 190)

Show table headers.

void show_headers (array $headers, string $type, [bool $sortable = true])
  • array $headers: column name => column title (for table heads)
  • string $type: type of list that is being shown
  • bool $sortable: whether or not to show sortable column headers (links in th's)
show_list (line 110)

Show a list of values, for forms.

void show_list (array $list, array $headers, [string $type = 'checkbox'], [mixed $actions = null], [string $form_id = null], [bool $sortable = true], [array|string $selected = null], array $array)
  • array $list: associative array
  • array $headers: column name => column title (for table heads)
  • string $type: checkbox, radio, simple
  • array $array: actions to display in actions select list
  • string $form_id: id of form holding list
  • bool $sortable: whether or not to show sortable column headers (links in th's)
  • array|string $selected: if type is checkbox, array otherwise string with one val
show_row (line 245)

Show table data.

void show_row (array $headers, array $row, string $type, [mixed $num = null], [array|string $selected = null])
  • array $headers: column name => column title (for knowing which ones to display)
  • array $row: table row, assoc
  • string $type: type of table, determines first column, which could be an input
  • array|string $selected: selected items; if type is checkbox, array otherwise string with one val

Documentation generated on Mon, 8 Nov 2004 13:43:04 -0800 by phpDocumentor 1.3.0RC3