Source for file core_display_functions.php

Documentation is available at core_display_functions.php

  1. <?php
  2.  
  3.  
  4.  
  5. function limitString( $string, $length = 15 ) {
  6.  
  7. if( strlen( $string ) >= $length ) {
  8.  
  9. $returnString = substr( $string, 0, ($length - 3) );
  10.  
  11. $returnString .= "...";
  12.  
  13. return $returnString;
  14.  
  15. } else { return $string; }
  16.  
  17. }
  18.  
  19.  
  20.  
  21. function mouseover( $start = "#999999", $over = "#000000") {
  22.  
  23. //inserts code to make links respond to mousover-ing
  24.  
  25. return 'onmouseover="this.style.color=\''.$over.'\'" onmouseout="this.style.color=\''.$start.'\'"';
  26.  
  27. }
  28.  
  29.  
  30.  
  31. function format_field( &$field, $object = NULL ) {
  32.  
  33. if( $field['src'] == 'var' ) {
  34.  
  35. //if the field is an object variable
  36.  
  37. if( $object ) {
  38.  
  39. return $object->get_attribute( $field['value'] );
  40.  
  41. } else {
  42.  
  43. return false;
  44.  
  45. }
  46.  
  47. } else if( $field['src'] == 'string' ) {
  48.  
  49. return $field['value'];
  50.  
  51. } else if( $field['src'] == 'compound' ) {
  52.  
  53. //NOTE: this may cause recursion...
  54.  
  55. foreach( $field['value'] as $element ) {
  56.  
  57. $returnString .= format_field( $element, $object );
  58.  
  59. }
  60.  
  61. return $returnString;
  62.  
  63. } else if( $field['src'] == 'switch' ) {
  64.  
  65. if( $_GET['module'] ) { $module = 'module='.$_GET['module'].'&'; }
  66.  
  67. switch( $field['value'] ){
  68.  
  69. case 'edit':
  70.  
  71. $field['class'] = "table_filled";
  72.  
  73. return '<a href="system_management.php?'.$module.'object_type='.$object->type->get_attribute( 'type_name' ).'&object='.$object->get_attribute( 'id' ).'" '.mouseover().'>edit</a>';
  74.  
  75. case 'delete':
  76.  
  77. $field['class'] = "table_delete";
  78.  
  79. 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>';
  80.  
  81. case 'address':
  82.  
  83. return address_form( $object );
  84.  
  85. }
  86.  
  87. }
  88.  
  89. }
  90.  
  91.  
  92.  
  93. function address_form( &$object ) {
  94.  
  95. $address = $object->get_attribute( 'address' );
  96.  
  97. if( !$object || !is_array( $address ) ) {
  98.  
  99. $returnString = '<p>address line 1 '.form_input( 'address_line1', NULL, NULL, 'form_address' ).'</p>';
  100.  
  101. $returnString .= '<p>address line 2 '.form_input( 'address_line2', NULL, NULL, 'form_address' ).'</p>';
  102.  
  103. $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>';
  104.  
  105. } else {
  106.  
  107. foreach( $address as $key => $value ) {
  108.  
  109. $compound;
  110.  
  111. switch( $key ) {
  112.  
  113. case 'line1':
  114.  
  115. if($compound){
  116.  
  117. $returnString .= $compound.'</p>';
  118.  
  119. unset($compound);
  120.  
  121. }
  122.  
  123. $returnString .= '<p>address line 1 '.form_input( 'address_line1', $value, NULL, 'form_address' ).'</p>';
  124.  
  125. break;
  126.  
  127. case 'line2':
  128.  
  129. if($compound){
  130.  
  131. $returnString .= $compound.'</p>';
  132.  
  133. unset($compound);
  134.  
  135. }
  136.  
  137. $returnString .= '<p>address line 2 '.form_input( 'address_line2', $value, NULL, 'form_address' ).'</p>';
  138.  
  139. break;
  140.  
  141. case 'city':
  142.  
  143. $compound .= '<p>city '.form_input( 'address_city', $value, NULL, 'form_city' );
  144.  
  145. break;
  146.  
  147. case 'state':
  148.  
  149. $compound .= '<p>state '.form_input( 'address_state', $value, NULL, 'form_state' );
  150.  
  151. break;
  152.  
  153. case 'zip':
  154.  
  155. $compound .= '<p>zipcode '.form_input( 'address_zip', $value, NULL, 'form_zip' );
  156.  
  157. break;
  158.  
  159. }
  160.  
  161. }
  162.  
  163. }
  164.  
  165. return $returnString;
  166.  
  167. }
  168.  
  169.  
  170.  
  171. function table( $content, $divName, $fieldArray = NULL, $orientation = NULL ) {
  172.  
  173. $returnString = '
  174.  
  175. <div id="'.$divName.'">
  176.  
  177. <table width="100%" cellpadding="4" bgcolor="#FFFFFF">
  178.  
  179. <tr>
  180.  
  181. <td colspan="'.count($fieldArray).'" bgcolor="#eeeeee" style="text-align: right;">&nbsp;</td>
  182.  
  183. </tr>
  184.  
  185. ';
  186.  
  187. if( $orientation == 'vert' && $fieldArray ) {
  188.  
  189. //for tables where each row needs a different display type
  190.  
  191. foreach( $fieldArray as $field ) {
  192.  
  193. $item = format_field( $field, $content );
  194.  
  195. $rowArray = array( array( 'type'=>'string', 'value'=>$field['label'], 'class'=>'table_filled' ), $field );
  196.  
  197. $returnString .= table_row( array('', $item), $rowArray );
  198.  
  199. }
  200.  
  201. } else if( $fieldArray ) {
  202.  
  203. //for tables where all rows are displayed the same
  204.  
  205. //construct labels
  206.  
  207. if( count($content) ) {
  208.  
  209. $output = array();
  210.  
  211. foreach( $fieldArray as $field ) {
  212.  
  213. if( $field['label'] ) {
  214.  
  215. $output[] = $field['label'];
  216.  
  217. $labelFields[] = array( 'type'=>'text', 'class'=>'table_filled' );
  218.  
  219. } else if( $field['src'] == 'var' ) {
  220.  
  221. $output[] = $field['value'];
  222.  
  223. $labelFields[] = array( 'type'=>'text', 'class'=>'table_filled' );
  224.  
  225. } else {
  226.  
  227. $output[] = '';
  228.  
  229. $labelFields[] = array( 'type'=>'text' );
  230.  
  231. }
  232.  
  233. }
  234.  
  235. $returnString .= table_row( $output, $labelFields );
  236.  
  237.  
  238. //format data and output
  239.  
  240. //NOTE: there may be an object/array conflict with the format_field function and passing by reference/value
  241.  
  242.  
  243. foreach( $content as $item ) {
  244.  
  245. $output = array();
  246.  
  247. $outputArray = array();
  248.  
  249. foreach( $fieldArray as $field ) {
  250.  
  251. $output[] = format_field( $field, $item );
  252.  
  253. $outputArray[] = $field;
  254.  
  255. }
  256.  
  257. $returnString .= table_row( $output, $outputArray );
  258.  
  259. }
  260.  
  261. } else {
  262.  
  263. $returnString .= table_row( array( 'none defined' ) );
  264.  
  265. }
  266.  
  267. } else {
  268.  
  269. $returnString .= '<tr><td><strong>ERROR:</strong> FIELD ARRAY NOT SPECIFIED</td></tr>';
  270.  
  271. }
  272.  
  273. $returnString .= '
  274.  
  275. <tr>
  276.  
  277. <td colspan="'.count($fieldArray).'" bgcolor="#eeeeee" style="text-align: right;">&nbsp;</td>
  278.  
  279. </tr>
  280.  
  281. </table>
  282.  
  283. </div>
  284.  
  285. ';
  286.  
  287.  
  288.  
  289. return $returnString;
  290.  
  291. }
  292.  
  293.  
  294.  
  295. function table_td( $content = NULL, $field = NULL ) {
  296.  
  297. if( $field['class'] ) {
  298.  
  299. $returnString .= '<td class="'.$field['class'].'">';
  300.  
  301. } else {
  302.  
  303. $returnString .= '<td>';
  304.  
  305. }
  306.  
  307. $returnString .= $content.' &nbsp; </td>';
  308.  
  309.  
  310. return $returnString;
  311.  
  312. }
  313.  
  314.  
  315.  
  316. function table_row( $content, $fieldArray = NULL ) {
  317.  
  318. $returnString = '<tr>';
  319.  
  320. if( $fieldArray ) {
  321.  
  322. for( $i=0; $i<count($fieldArray); $i++ ) {
  323.  
  324. if( $fieldArray[$i]['type'] == "text" ) {
  325.  
  326. //text table entry
  327.  
  328. $returnString .= table_td( $content[$i], $fieldArray[$i] );
  329.  
  330. } else if( $fieldArray[$i]['type'] == "input" ) {
  331.  
  332. //standard form input
  333.  
  334. $returnString .= table_td( form_input( $fieldArray[$i]['value'], $content[$i] ), $fieldArray[$i] );
  335.  
  336. } else if( $fieldArray[$i]['type'] == "textarea" ) {
  337.  
  338. //textarea form input
  339.  
  340. $returnString .= table_td( form_textarea( $fieldArray[$i]['value'], $content[$i] ), $fieldArray[$i] );
  341.  
  342. } else if( $fieldArray[$i]['type'] == "datetime" ) {
  343.  
  344. //text field
  345.  
  346. $returnString .= table_td( date( 'D M d, Y', strtotime($content[$i])).' | '.date( 'h:m a', strtotime($content[$i])), $fieldArray[$i] );
  347.  
  348. } else if( $fieldArray[$i]['type'] == "password" ) {
  349.  
  350. //password form input
  351.  
  352. $returnString .= table_td( form_input( 'password', NULL, true ), $fieldArray[$i] );
  353.  
  354. } else if( $fieldArray[$i]['type'] == "string" ) {
  355.  
  356. //string table entry
  357.  
  358. $returnString .= table_td( $fieldArray[$i]['value'], $fieldArray[$i] );
  359.  
  360. } else if( $fieldArray[$i]['type'] == "form_select" ) {
  361.  
  362. //NOTE: not quite sure what to do with this...
  363.  
  364. } else {
  365.  
  366. $returnString .= table_td( $content[$i], $fieldArray[$i] );
  367.  
  368. }
  369.  
  370. }
  371.  
  372.  
  373.  
  374. } else {
  375.  
  376. foreach( $content as $output ) {
  377.  
  378. $returnString .= '<td>'.$output.' &nbsp;</td>';
  379.  
  380. }
  381.  
  382. }
  383.  
  384. $returnString .= '</tr>';
  385.  
  386.  
  387. return $returnString;
  388.  
  389. }
  390.  
  391.  
  392.  
  393. function echo_gets( $returnString = false, $omitArray = array() ) {
  394.  
  395. //returns a string with any variables passed as a GET
  396.  
  397. //NOTE: returnString variable not being used
  398.  
  399. $returnString = "?";
  400.  
  401. $getKeys = array_keys( $_GET );
  402.  
  403.  
  404. for($i=0;$i<count($getKeys);$i++) {
  405.  
  406. if( !in_array( $getKeys[$i], $omitArray ) ) {
  407.  
  408. $returnString .= ($i?"&":"").$getKeys[$i]."=".$_GET[$getKeys[$i]];
  409.  
  410. }
  411.  
  412. }
  413.  
  414. if( !$returnString ) { echo $returnString; }
  415.  
  416. else { return $returnString; }
  417.  
  418. }
  419.  
  420.  
  421.  
  422. function echo_url( $stringReturn = false, $includeGets = true, $omitArray = array() ) {
  423.  
  424. //returns the URL of the page currently being viewed
  425.  
  426. //NOTE: stringReturn not being used
  427.  
  428. $returnString = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
  429.  
  430.  
  431.  
  432. if( $includeGets ) { $returnString .= echo_gets( true, $omitArray ); }
  433.  
  434.  
  435.  
  436. if( !$stringReturn ) { echo $returnString; }
  437.  
  438. else { return $returnString; }
  439.  
  440. }
  441.  
  442.  
  443.  
  444. function focus( $blur = "#fff", $focus = "#E9E9E9") {
  445.  
  446. //inserts code to change the background of a form element when it is being edited
  447.  
  448. return 'onfocus="this.style.background=\''.$focus.'\'" onblur="this.style.background=\''.$blur.'\'"';
  449.  
  450. }
  451.  
  452.  
  453.  
  454. function form_input( $name, $value = NULL, $password = NULL, $class = 'form_input' ) {
  455.  
  456. //inserts a single-line form input with the specified values
  457.  
  458. if( isset( $GLOBALS['errorArray'] ) ) { $errorArray = $GLOBALS['errorArray']; }
  459.  
  460. else { $errorArray = array(); }
  461.  
  462.  
  463. if( !array_key_exists( $name, $errorArray ) ) {
  464.  
  465. return '<input class="'.$class.'" '.($password? 'type="password" ' : '' ).'name="'.$name.'" '.($value?'value="'.$value.'"':'').' '.focus().' onKeyPress="submitenter(this,event)">';
  466.  
  467. } else {
  468.  
  469. return error_text($name).'<input class="'.$class.'" '.($password? 'type="password" ' : '' ).'style="background:#F2B5B3;" name="'.$name.'" '.($value?'value="'.$value.'"':'').' onKeyPress="submitenter(this,event)">';
  470.  
  471. }
  472.  
  473. }
  474.  
  475.  
  476.  
  477. function form_textarea( $name, $value = NULL ) {
  478.  
  479. //inserts a multi-line form input with the specified values
  480.  
  481. //NOTE: this is currently returning a tinyMCE-enabled textarea - to change remove the mce_editable tag
  482.  
  483. if( isset( $GLOBALS['errorArray'] ) ) { $errorArray = $GLOBALS['errorArray']; }
  484.  
  485. else { $errorArray = array(); }
  486.  
  487.  
  488.  
  489. if( !in_array( $name, $errorArray ) ) {
  490.  
  491. return '<textarea mce_editable="false" rows="10" class="form_input" name="'.$name.'" '.focus().'>'.$value.'</textarea>';
  492.  
  493. } else {
  494.  
  495. return '<textarea mce_editable="false" rows="10" class="form_input" style="background:#F2B5B3;" name="'.$name.'">'.$value.'</textarea>';
  496.  
  497. }
  498.  
  499. }
  500.  
  501.  
  502.  
  503.  
  504.  
  505. function core_get_modules_table() {
  506.  
  507. //echos a table with current module information
  508.  
  509. $returnString;
  510.  
  511. $returnString .= '
  512.  
  513. <table width="100%" cellpadding="4" bgcolor="#FFFFFF">
  514.  
  515. <tr>
  516.  
  517. <td bgcolor="#eeeeee">name</td>
  518.  
  519. <td bgcolor="#eeeeee">description</td>
  520.  
  521. <td bgcolor="#eeeeee">homepage</td>
  522.  
  523. <td bgcolor="#eeeeee">location</td>
  524.  
  525. <td bgcolor="#eeeeee">activation</td>
  526.  
  527. <td>&nbsp;</td>
  528.  
  529. </tr>
  530.  
  531. ';
  532.  
  533. $modules = retrieve_installed_modules();
  534.  
  535. foreach( $modules as $module ) {
  536.  
  537. $returnString .= '
  538.  
  539. <tr>
  540.  
  541. <td>'.$module['module_icon'].$module['module_name'].'</td>
  542.  
  543. <td bgcolor="#eeeeee">'.$module['module_description'].'</td>
  544.  
  545. <td>'."/Modules/".$module['module_location'].'</td>
  546.  
  547. <td bgcolor="#eeeeee">'.$module['module_page'].'</td>
  548.  
  549. <td>
  550.  
  551. ';
  552.  
  553. if($module['module_activated']){
  554.  
  555. $returnString .= '<a href="core.php?action=deactivate&value='.$module['module_name'].'"'.mouseover().'>deactivate';
  556.  
  557. } else {
  558.  
  559. $returnString .= '<a href="core.php?action=activate&value='.$module['module_name'].'"'.mouseover().'>activate';
  560.  
  561. }
  562.  
  563. $returnString .= '</td>
  564.  
  565. <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>
  566.  
  567. </tr>
  568.  
  569. ';
  570.  
  571. }
  572.  
  573. $returnString .='
  574.  
  575. </table>
  576.  
  577. ';
  578.  
  579.  
  580. return $returnString;
  581.  
  582. }
  583.  
  584.  
  585.  
  586. function core_get_settings() {
  587.  
  588. //echos a table with current core settings
  589.  
  590. $returnString;
  591.  
  592. $returnString .= '
  593.  
  594. <table width="100%" cellpadding="4" bgcolor="#FFFFFF">
  595.  
  596. <tr>
  597.  
  598. <td bgcolor="#eeeeee">setting</td>
  599.  
  600. <td bgcolor="#eeeeee">value</td>
  601.  
  602. </tr>
  603.  
  604. ';
  605.  
  606. $settings = get_core_settings();
  607.  
  608. foreach( $settings as $setting ){
  609.  
  610. $returnString .= '
  611.  
  612. <tr>
  613.  
  614. <td bgcolor="#eeeeee">'.$setting['name'].'</td>
  615.  
  616. <td>'.$setting['value'].'</td>
  617.  
  618. </tr>
  619.  
  620. ';
  621.  
  622. }
  623.  
  624. $returnString .= '</table>';
  625.  
  626.  
  627. return $returnString;
  628.  
  629. }
  630.  
  631.  
  632.  
  633. function insert_corners( $color = "989898" ) {
  634.  
  635. //echos images to be used for rounded corners
  636.  
  637. return '
  638.  
  639. <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/tl_'.$color.'.gif" class="corner_tl"/>
  640.  
  641. <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/tr_'.$color.'.gif" class="corner_tr"/>
  642.  
  643. <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/bl_'.$color.'.gif" class="corner_bl"/>
  644.  
  645. <img src="http://'.$_SERVER['HTTP_HOST'].'/pi/Core_Resources/Images/br_'.$color.'.gif" class="corner_br"/>
  646.  
  647. ';
  648.  
  649. }
  650.  
  651.  
  652.  
  653. function core_insert_start_page() {
  654.  
  655. //echos the current default start page
  656.  
  657. global $db;
  658.  
  659.  
  660. $returnValue = $db->get_var( "SELECT value FROM core_settings WHERE name = 'start_page'" );
  661.  
  662. return $returnValue;
  663.  
  664. }
  665.  
  666.  
  667.  
  668. function print_array( $array ) {
  669.  
  670. echo '<pre>'.str_replace(array("\n" , " "), array('<br>', '&nbsp;'), print_r($array, true)).'</pre>';
  671.  
  672. }
  673.  
  674.  
  675.  
  676. ?>

Documentation generated on Tue, 24 May 2005 03:57:46 -0400 by phpDocumentor 1.3.0RC3