Documentation is available at core_display_functions.php
- <?php
- function limitString( $string, $length = 15 ) {
- if( strlen( $string ) >= $length ) {
- $returnString = substr( $string, 0, ($length - 3) );
- $returnString .= "...";
- return $returnString;
- } else { return $string; }
- }
- function mouseover( $start = "#999999", $over = "#000000") {
- //inserts code to make links respond to mousover-ing
- return 'onmouseover="this.style.color=\''.$over.'\'" onmouseout="this.style.color=\''.$start.'\'"';
- }
- function format_field( &$field, $object = NULL ) {
- if( $field['src'] == 'var' ) {
- //if the field is an object variable
- if( $object ) {
- return $object->get_attribute( $field['value'] );
- } else {
- return false;
- }
- } else if( $field['src'] == 'string' ) {
- return $field['value'];
- } else if( $field['src'] == 'compound' ) {
- //NOTE: this may cause recursion...
- foreach( $field['value'] as $element ) {
- $returnString .= format_field( $element, $object );
- }
- return $returnString;
- } else if( $field['src'] == 'switch' ) {
- if( $_GET['module'] ) { $module = 'module='.$_GET['module'].'&'; }
- switch( $field['value'] ){
- case 'edit':
- $field['class'] = "table_filled";
- return '<a href="system_management.php?'.$module.'object_type='.$object->type->get_attribute( 'type_name' ).'&object='.$object->get_attribute( 'id' ).'" '.mouseover().'>edit</a>';
- case 'delete':
- $field['class'] = "table_delete";
- return '<a href="#" '.mouseover().' onclick="redirectConfirm( \''.echo_url(true,false).'?'.$module.'object_type='.$object->type->get_attribute( 'type_name' ).'&object='.$object->get_attribute( 'id' ).'&action=delete\', \'are you sure you want to delete '.$object->get_index().'?\')" style="color:#fff;">delete</a>';
- case 'address':
- return address_form( $object );
- }
- }
- }
- function address_form( &$object ) {
- $address = $object->get_attribute( 'address' );
- if( !$object || !is_array( $address ) ) {
- $returnString = '<p>address line 1 '.form_input( 'address_line1', NULL, NULL, 'form_address' ).'</p>';
- $returnString .= '<p>address line 2 '.form_input( 'address_line2', NULL, NULL, 'form_address' ).'</p>';
- $returnString .= '<p>city '.form_input( 'address_city', NULL, NULL, 'form_city' ).' state '.form_input( 'address_state', NULL, NULL, 'form_state' ).' zipcode '.form_input( 'address_zip', NULL, NULL, 'form_zip' ).'</p>';
- } else {
- foreach( $address as $key => $value ) {
- $compound;
- switch( $key ) {
- case 'line1':
- if($compound){
- $returnString .= $compound.'</p>';
- unset($compound);
- }
- $returnString .= '<p>address line 1 '.form_input( 'address_line1', $value, NULL, 'form_address' ).'</p>';
- break;
- case 'line2':
- if($compound){
- $returnString .= $compound.'</p>';
- unset($compound);
- }
- $returnString .= '<p>address line 2 '.form_input( 'address_line2', $value, NULL, 'form_address' ).'</p>';
- break;
- case 'city':
- $compound .= '<p>city '.form_input( 'address_city', $value, NULL, 'form_city' );
- break;
- case 'state':
- $compound .= '<p>state '.form_input( 'address_state', $value, NULL, 'form_state' );
- break;
- case 'zip':
- $compound .= '<p>zipcode '.form_input( 'address_zip', $value, NULL, 'form_zip' );
- break;
- }
- }
- }
- return $returnString;
- }
- function table( $content, $divName, $fieldArray = NULL, $orientation = NULL ) {
- $returnString = '
- <div id="'.$divName.'">
- <table width="100%" cellpadding="4" bgcolor="#FFFFFF">
- <tr>
- <td colspan="'.count($fieldArray).'" bgcolor="#eeeeee" style="text-align: right;"> </td>
- </tr>
- ';
- if( $orientation == 'vert' && $fieldArray ) {
- //for tables where each row needs a different display type
- foreach( $fieldArray as $field ) {
- $item = format_field( $field, $content );
- $rowArray = array( array( 'type'=>'string', 'value'=>$field['label'], 'class'=>'table_filled' ), $field );
- $returnString .= table_row( array('', $item), $rowArray );
- }
- } else if( $fieldArray ) {
- //for tables where all rows are displayed the same
- //construct labels
- if( count($content) ) {
- $output = array();
- foreach( $fieldArray as $field ) {
- if( $field['label'] ) {
- $output[] = $field['label'];
- $labelFields[] = array( 'type'=>'text', 'class'=>'table_filled' );
- } else if( $field['src'] == 'var' ) {
- $output[] = $field['value'];
- $labelFields[] = array( 'type'=>'text', 'class'=>'table_filled' );
- } else {
- $output[] = '';
- $labelFields[] = array( 'type'=>'text' );
- }
- }
- $returnString .= table_row( $output, $labelFields );
- //format data and output
- //NOTE: there may be an object/array conflict with the format_field function and passing by reference/value
- foreach( $content as $item ) {
- $output = array();
- $outputArray = array();
- foreach( $fieldArray as $field ) {
- $output[] = format_field( $field, $item );
- $outputArray[] = $field;
- }
- $returnString .= table_row( $output, $outputArray );
- }
- } else {
- $returnString .= table_row( array( 'none defined' ) );
- }
- } else {
- $returnString .= '<tr><td><strong>ERROR:</strong> FIELD ARRAY NOT SPECIFIED</td></tr>';
- }
- $returnString .= '
- <tr>
- <td colspan="'.count($fieldArray).'" bgcolor="#eeeeee" style="text-align: right;"> </td>
- </tr>
- </table>
- </div>
- ';
- return $returnString;
- }
- function table_td( $content = NULL, $field = NULL ) {
- if( $field['class'] ) {
- $returnString .= '<td class="'.$field['class'].'">';
- } else {
- $returnString .= '<td>';
- }
- $returnString .= $content.' </td>';
- return $returnString;
- }
- function table_row( $content, $fieldArray = NULL ) {
- $returnString = '<tr>';
- if( $fieldArray ) {
- for( $i=0; $i<count($fieldArray); $i++ ) {
- if( $fieldArray[$i]['type'] == "text" ) {
- //text table entry
- $returnString .= table_td( $content[$i], $fieldArray[$i] );
- } else if( $fieldArray[$i]['type'] == "input" ) {
- //standard form input
- $returnString .= table_td( form_input( $fieldArray[$i]['value'], $content[$i] ), $fieldArray[$i] );
- } else if( $fieldArray[$i]['type'] == "textarea" ) {
- //textarea form input
- $returnString .= table_td( form_textarea( $fieldArray[$i]['value'], $content[$i] ), $fieldArray[$i] );
- } else if( $fieldArray[$i]['type'] == "datetime" ) {
- //text field
- $returnString .= table_td( date( 'D M d, Y', strtotime($content[$i])).' | '.date( 'h:m a', strtotime($content[$i])), $fieldArray[$i] );
- } else if( $fieldArray[$i]['type'] == "password" ) {
- //password form input
- $returnString .= table_td( form_input( 'password', NULL, true ), $fieldArray[$i] );
- } else if( $fieldArray[$i]['type'] == "string" ) {
- //string table entry
- $returnString .= table_td( $fieldArray[$i]['value'], $fieldArray[$i] );
- } else if( $fieldArray[$i]['type'] == "form_select" ) {
- //NOTE: not quite sure what to do with this...
- } else {
- $returnString .= table_td( $content[$i], $fieldArray[$i] );
- }
- }
- } else {
- foreach( $content as $output ) {
- $returnString .= '<td>'.$output.' </td>';
- }
- }
- $returnString .= '</tr>';
- return $returnString;
- }
- function echo_gets( $returnString = false, $omitArray = array() ) {
- //returns a string with any variables passed as a GET
- //NOTE: returnString variable not being used
- $returnString = "?";
- $getKeys = array_keys( $_GET );
- for($i=0;$i<count($getKeys);$i++) {
- if( !in_array( $getKeys[$i], $omitArray ) ) {
- $returnString .= ($i?"&":"").$getKeys[$i]."=".$_GET[$getKeys[$i]];
- }
- }
- if( !$returnString ) { echo $returnString; }
- else { return $returnString; }
- }
- function echo_url( $stringReturn = false, $includeGets = true, $omitArray = array() ) {
- //returns the URL of the page currently being viewed
- //NOTE: stringReturn not being used
- $returnString = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
- if( $includeGets ) { $returnString .= echo_gets( true, $omitArray ); }
- if( !$stringReturn ) { echo $returnString; }
- else { return $returnString; }
- }
- function focus( $blur = "#fff", $focus = "#E9E9E9") {
- //inserts code to change the background of a form element when it is being edited
- return 'onfocus="this.style.background=\''.$focus.'\'" onblur="this.style.background=\''.$blur.'\'"';
- }
- function form_input( $name, $value = NULL, $password = NULL, $class = 'form_input' ) {
- //inserts a single-line form input with the specified values
- if( isset( $GLOBALS['errorArray'] ) ) { $errorArray = $GLOBALS['errorArray']; }
- else { $errorArray = array(); }
- if( !array_key_exists( $name, $errorArray ) ) {
- return '<input class="'.$class.'" '.($password? 'type="password" ' : '' ).'name="'.$name.'" '.($value?'value="'.$value.'"':'').' '.focus().' onKeyPress="submitenter(this,event)">';
- } else {
- return error_text($name).'<input class="'.$class.'" '.($password? 'type="password" ' : '' ).'style="background:#F2B5B3;" name="'.$name.'" '.($value?'value="'.$value.'"':'').' onKeyPress="submitenter(this,event)">';
- }
- }
- function form_textarea( $name, $value = NULL ) {
- //inserts a multi-line form input with the specified values
- //NOTE: this is currently returning a tinyMCE-enabled textarea - to change remove the mce_editable tag
- if( isset( $GLOBALS['errorArray'] ) ) { $errorArray = $GLOBALS['errorArray']; }
- else { $errorArray = array(); }
- if( !in_array( $name, $errorArray ) ) {
- return '<textarea mce_editable="false" rows="10" class="form_input" name="'.$name.'" '.focus().'>'.$value.'</textarea>';
- } else {
- return '<textarea mce_editable="false" rows="10" class="form_input" style="background:#F2B5B3;" name="'.$name.'">'.$value.'</textarea>';
- }
- }
- function core_get_modules_table() {
- //echos a table with current module information
- $returnString;
- $returnString .= '
- <table width="100%" cellpadding="4" bgcolor="#FFFFFF">
- <tr>
- <td bgcolor="#eeeeee">name</td>
- <td bgcolor="#eeeeee">description</td>
- <td bgcolor="#eeeeee">homepage</td>
- <td bgcolor="#eeeeee">location</td>
- <td bgcolor="#eeeeee">activation</td>
- <td> </td>
- </tr>
- ';
- $modules = retrieve_installed_modules();
- foreach( $modules as $module ) {
- $returnString .= '
- <tr>
- <td>'.$module['module_icon'].$module['module_name'].'</td>
- <td bgcolor="#eeeeee">'.$module['module_description'].'</td>
- <td>'."/Modules/".$module['module_location'].'</td>
- <td bgcolor="#eeeeee">'.$module['module_page'].'</td>
- <td>
- ';
- if($module['module_activated']){
- $returnString .= '<a href="core.php?action=deactivate&value='.$module['module_name'].'"'.mouseover().'>deactivate';
- } else {
- $returnString .= '<a href="core.php?action=activate&value='.$module['module_name'].'"'.mouseover().'>activate';
- }
- $returnString .= '</td>
- <td bgcolor="#F2B5B3"><a href="#" style="color:#fff;" '.mouseover( "#fff", "#B90000").' onclick="if(confirm(\'are you sure you want to uninstall the module '.$module['module_name'].'?\')){MM_goToURL(\'parent\',\'core.php?action=uninstall&value='.$module['module_name'].'\');return document.MM_returnValue}">uninstall</a></td>
- </tr>
- ';
- }
- $returnString .='
- </table>
- ';
- return $returnString;
- }
- function core_get_settings() {
- //echos a table with current core settings
- $returnString;
- $returnString .= '
- <table width="100%" cellpadding="4" bgcolor="#FFFFFF">
- <tr>
- <td bgcolor="#eeeeee">setting</td>
- <td bgcolor="#eeeeee">value</td>
- </tr>
- ';
- $settings = get_core_settings();
- foreach( $settings as $setting ){
- $returnString .= '
- <tr>
- <td bgcolor="#eeeeee">'.$setting['name'].'</td>
- <td>'.$setting['value'].'</td>
- </tr>
- ';
- }
- $returnString .= '</table>';
- return $returnString;
- }
- function insert_corners( $color = "989898" ) {
- //echos images to be used for rounded corners
- return '
- <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/tl_'.$color.'.gif" class="corner_tl"/>
- <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/tr_'.$color.'.gif" class="corner_tr"/>
- <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/bl_'.$color.'.gif" class="corner_bl"/>
- <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/br_'.$color.'.gif" class="corner_br"/>
- ';
- }
- function core_insert_start_page() {
- //echos the current default start page
- global $db;
- $returnValue = $db->get_var( "SELECT value FROM core_settings WHERE name = 'start_page'" );
- return $returnValue;
- }
- function print_array( $array ) {
- echo '<pre>'.str_replace(array("\n" , " "), array('<br>', ' '), print_r($array, true)).'</pre>';
- }
- ?>
Documentation generated on Tue, 24 May 2005 03:57:46 -0400 by phpDocumentor 1.3.0RC3